Skip to content
This repository was archived by the owner on Aug 31, 2024. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,27 @@ stream.toArray(function (err, arr) {
})
```

If `callback` is not defined, then it is assumed that it is being yielded within a generator.
If `callback` is not defined, then it returns a promise.

```js
function* () {
var stream = new Stream.Readable()
stream.toArray = toArray
var arr = yield stream.toArray()
}
toArray(stream)
.then(function (parts) {

})
```

If you want to return a buffer, just use `Buffer.concat(arr)`

```js
var stream = new Stream.Readable()
var arr = yield toArray(stream)
var buffer = Buffer.concat(arr)
toArray(stream)
.then(function (parts) {
var buffers = []
for (var i = 0, l = parts.length; i < l ; ++i) {
var part = parts[i]
buffers.push((part instanceof Buffer) ? part : new Buffer(part))
}
return Buffer.concat(buffers)
})
```

[npm-image]: https://img.shields.io/npm/v/stream-to-array.svg?style=flat-square
Expand Down