highland icon indicating copy to clipboard operation
highland copied to clipboard

Highland.js and something like busboy

Open kharandziuk opened this issue 10 years ago • 0 comments

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

The Same question on StackOverflow

kharandziuk avatar Nov 25 '15 21:11 kharandziuk