highland
highland copied to clipboard
Highland.js and something like busboy
It is easy to wrap simple EventEmitter or ReadableStream, but how should I work with something like busboy. It doesn't implement ReadableStream interface. I finished with code below, but it doesn't look idiomatic:
H(function(push) {
busboy.on('file', (fieldname, file, filename, encoding, mimetype)=> {
let saveTo = path.resolve(mediaPath, "#{name}#{extension}")
file.pipe(fs.createWriteStream(saveTo))
push(null, {
[fieldname]: { filename }
})
})
busboy.on('field', (key, value, keyTruncated, valueTruncated) => {
push(null, {[key]: value})
})
busboy.on('finish', () =>
push(null, H.nil)
)
})
.reduce({}, _.extend)
.apply(// do something with form data