Skip to content

Commit

Permalink
Resolve object mode as an array of objects
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
bendrucker committed Jun 18, 2016
1 parent dae1d7d commit ff4c10f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function fromReadable (stream) {

return promise
.then(function concat (parts) {
if (stream._readableState && stream._readableState.objectMode) {
return parts
}
return Buffer.concat(parts.map(bufferize))
})
}
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ describe('stream-to-promise', function () {
})
})

it('returns an array for object streams', function () {
var objectStream = new Stream.Readable({objectMode: true})
objectStream._read = function noop () {}
var promise = streamToPromise(objectStream)
objectStream.emit('data', {foo: 'bar'})
objectStream.emit('data', {baz: 'qux'})
objectStream.emit('end')
return promise.then(function (results) {
expect(results).to.deep.equal([{foo: 'bar'}, {baz: 'qux'}])
})
})

it('rejects on stream errors', function () {
var err = new Error()
readable.emit('error', err)
Expand Down

0 comments on commit ff4c10f

Please sign in to comment.