pond
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

pond CI

commits

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.

Readme

Keywords

Package Sidebar

Install

npm i pond

Weekly Downloads

3,105

Version

2.1.2

License

MIT

Unpacked Size

8.46 kB

Total Files

6

Last publish

Collaborators

  • xingrz