npm.io
2.1.2 • Published 5 years ago

pond

Licence
MIT
Version
2.1.2
Deps
1
Size
8 kB
Vulns
0
Weekly
0
Stars
1
DeprecatedThis package is deprecated

pond CI

[![][issues-img]][issues-url] [![commits][commits-img]][commits-url]

Collect a stream into a buffer.

Please aware that, because buffers came out from a stream are buffered into the memory, DO NOT try to collect a stream that is large or with unknowable length!

import { createReadStream } from 'fs';
import { createHash } from 'crypto';
import pond from 'pond';

const digest = await createReadStream('/path/to/some/file')
  .pipe(createHash('sha256'))
  .pipe(pond())
  .spoon();

console.log(digest.toString('hex'));

Requirements

Node >= 10, tested on latest Node and latest LTS Node.

Installation

npm install --save pond

Usage

Promise, await
const buffer = await stream.pipe(pond()).spoon();
const buffer = await pond(stream).spoon();
Stream API (piping):
fs.createReadStream('somefile')
  .pipe(pond())
  .on('error', (err) => {
    // ...
  })
  .spoon((buffer) => {
    // ...
  });
Or, old-fashioned callback:
pond(fs.createReadStream('anotherfile'), function (err, buffer) {
  // ...
});

Test

npm test

License

This project is released under the terms of MIT License.

[issues-img]: https://img.shields.io/github/issues/xingrz/pond.svg?style=flat-square [issues-url]: https://github.com/xingrz/pond/issues [commits-img]: https://img.shields.io/github/last-commit/xingrz/pond?style=flat-square [commits-url]: https://github.com/xingrz/pond/commits/master

Keywords