1.1.3 • Published 4 years ago

stream-get-reader v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

stream-get-reader

Stream reader, something like ReadableStream.getReader

npm install stream-get-reader

Usage

import {getStreamReader} from "stream-get-reader";
import {Readable} from "stream";

const stream = Readable.from(Buffer.alloc(1024 * 1024));
const reader = getStreamReader(stream);

while(true) {
    const {done, value} = await reader.read();
    if (done) break;
    console.log(value);
}

API

new StreamReader(Readable)

import StreamReader from "stream-get-reader";
import {Readable} from "stream";

const stream = Readable.from(Buffer.alloc(1024 * 1024));
const reader = new StreamReader(stream);

const {done, value} = await reader.read();

reader.destroy();

reader.read()

  • Returns: Promise<{done: true, value: undefined} | {done: false, value: Buffer}>

The reader.read() method pulls some value out of the buffer and returns it. If stream emit error, it throws error when buffer will be empty. If reader was destroyed it throw error if it was provided or will be done.

reader.destroy(error)

  • error <Error> Optional an error

Destroy the reader and optionally provide an error. When you call reader.destroy(), it calls Readable.destroy(error) too.

1.1.1

4 years ago

1.1.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago