request/lib/urlencoded_parser.js

28 lines
491 B
JavaScript
Raw Normal View History

2023-10-27 19:16:32 +08:00
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/10/27 12:14:05
*/
import { parse } from 'node:querystring'
import { EventEmitter } from 'node:events'
export class UrlencodedParser extends EventEmitter {
#buff = Buffer.from('')
write(buffer) {
this.#buff = Buffer.concat([this.#buff, buffer])
}
end() {
let data = this.#buff.toString()
let fields = parse(data)
this.#buff = null
this.emit('field', fields)
this.emit('end')
}
}