https://github.com/caub/as-buffer
Convert a stream (or string, array) to buffer
https://github.com/caub/as-buffer
Last synced: 3 months ago
JSON representation
Convert a stream (or string, array) to buffer
- Host: GitHub
- URL: https://github.com/caub/as-buffer
- Owner: caub
- Created: 2017-04-24T14:21:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-13T09:31:08.000Z (about 8 years ago)
- Last Synced: 2025-02-28T15:26:21.091Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Read stream and other types as buffer\*
[![npm version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![coverage status][codecov-image]][codecov-url]
```js
const read = require('as-buffer');
const stream = fs.createReadStream('./photo.png');
read(stream, { maxsize: 1e6 }) // with a max-size, default to 1e7, 10MiB
.then(buf => console.log('read', buf))
.catch(e => console.log('file too large'));
```
\*: exception of object-mode streams that are returned as array
like https://github.com/stream-utils/stream-to-array but simpler
[npm-image]: https://img.shields.io/npm/v/as-buffer.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/as-buffer
[travis-image]: https://img.shields.io/travis/caub/as-buffer.svg?style=flat-square
[travis-url]: https://travis-ci.org/caub/as-buffer
[codecov-image]: https://img.shields.io/codecov/c/github/caub/as-buffer.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/caub/as-buffer