https://github.com/feross/stream-with-known-length-to-buffer
Convert a Readable Stream with a known length into a Buffer
https://github.com/feross/stream-with-known-length-to-buffer
buffer javascript nodejs readable stream streams
Last synced: 10 months ago
JSON representation
Convert a Readable Stream with a known length into a Buffer
- Host: GitHub
- URL: https://github.com/feross/stream-with-known-length-to-buffer
- Owner: feross
- License: mit
- Created: 2015-12-29T20:22:11.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-17T04:34:15.000Z (almost 6 years ago)
- Last Synced: 2025-07-04T02:51:39.688Z (11 months ago)
- Topics: buffer, javascript, nodejs, readable, stream, streams
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stream-with-known-length-to-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
[travis-image]: https://img.shields.io/travis/feross/stream-with-known-length-to-buffer/master.svg
[travis-url]: https://travis-ci.org/feross/stream-with-known-length-to-buffer
[npm-image]: https://img.shields.io/npm/v/stream-with-known-length-to-buffer.svg
[npm-url]: https://npmjs.org/package/stream-with-known-length-to-buffer
[downloads-image]: https://img.shields.io/npm/dm/stream-with-known-length-to-buffer.svg
[downloads-url]: https://npmjs.org/package/stream-with-known-length-to-buffer
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com
#### Convert a Readable Stream with a known length into a Buffer
[](https://saucelabs.com/u/stream-with)
This package converts a Readable Stream into a Buffer, with just one Buffer
allocation (excluding allocations done internally by the streams implementation).
This is lighter-weight choice than
[`stream-to-array`](https://github.com/stream-utils/stream-to-array) when the
total stream length is known in advance. This whole package is 15 lines.
This module is used by [WebTorrent](https://webtorrent.io).
### install
```
npm install stream-with-known-length-to-buffer
```
### usage
```js
var toBuffer = require('stream-with-known-length-to-buffer')
toBuffer(fs.createReadStream('file.txt'), 1000, function (err, buf) {
if (err) return console.error(err.message)
console.log(buf)
})
```
### license
MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).