caolan / caolan/highland

Highland.js and something like busboy

Open
#405 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

It is easy to wrap simple EventEmitter or ReadableStream, but how should I work with something like [busboy](https://github.com/mscdex/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](http://stackoverflow.com/posts/33926718/edit)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.