let { Writable } = require('stream') module.exports = function parseParams(max, cb) { let buffers = [], bytes = 0 return new Writable({ write(buf, enc, next) { bytes += buf.length if (bytes > max) { cb(new Error(`params exceed maximum size (${max} bytes)`)) buffers = null this.destroy() } else { buffers.push(buf) next() } }, final(next) { cb(null, new URLSearchParams(Buffer.concat(buffers).toString())) next() }, }) }