@cookielab.io/stream-async-wrappers
    TypeScript icon, indicating that this package has built-in type declarations

    0.5.0 • Public • Published

    Stream Async Wrappers

    Installation

    $ yarn add @cookielab.io/stream-async-wrappers

    Usage

    Read data from stream

    import {ReadableStreamAsyncReader} from '@cookielab.io/stream-async-wrappers';
     
    const reader = new ReadableStreamAsyncReader(stream); // wrap readable stream
     
    const chunk = await reader.read(); // read chunk of data

    Write data into stream

    import {WritableStreamAsyncReader} from '@cookielab.io/stream-async-wrappers';
     
    const writer = new WritableStreamAsyncWriter(stream);
     
    await writer.write(chunk); // write chunk of data
     
    await writer.end(); // ends wrapped write stream

    API

    new WritableStreamAsyncWriter(stream: Writable)

    Creates an instance of writer by wrapping Node's Writable stream.

    writableStreamAsyncWriter.write(chunk: string | Buffer | any, encoding?: string, callback?: (error?: Error | null) => void): Promise<void>

    Writes given chunk of data into the wrapped stream. The returned promise will resolve once the data is successfully written into the wrapped write stream. The returned promise will reject with an error when the write fails. The optional callback argument is called just before the returned promise resolves or rejects.

    writableStreamAsyncWriter.end(callback?: (error?: Error | null) => void): Promise<void>

    Ends wrapped write stream after all data has been successfully written into the stream. The returned promise will resolve once the stream successfully finishes. The returned promise will reject with an error when the write or end fails.

    new ReadableStreamAsyncReader(stream: Readable)

    Creates an instance of reader by wrapping Node's Readable stream.

    readableStreamAsyncReader.read(size?: number): Promise<Chunk | null | undefined>

    Reads chunk of data from the wrapped stream. The optional size argument can be used to specify how much data to read. The returned promise will resolve with read data once they are available. The returned promise will reject with an error when the read fails.

    Keywords

    none

    Install

    npm i @cookielab.io/stream-async-wrappers

    DownloadsWeekly Downloads

    17

    Version

    0.5.0

    License

    MIT

    Unpacked Size

    11.5 kB

    Total Files

    13

    Last publish

    Collaborators

    • clbbot
    • markatom
    • stekycz
    • vrtak-cz