stream-with-known-length-to-buffer

1.0.4 • Public • Published

stream-with-known-length-to-buffer travis npm downloads javascript style guide

Convert a Readable Stream with a known length into a Buffer

Sauce Test Status

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 when the total stream length is known in advance. This whole package is 15 lines.

This module is used by WebTorrent.

install

npm install stream-with-known-length-to-buffer

usage

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.

Package Sidebar

Install

npm i stream-with-known-length-to-buffer

Weekly Downloads

876

Version

1.0.4

License

MIT

Unpacked Size

4.71 kB

Total Files

4

Last publish

Collaborators

  • feross