🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@cookielab.io/stream-async-wrappers

Package Overview
Dependencies
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cookielab.io/stream-async-wrappers

## Installation

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
5.9K
24.73%
Maintainers
4
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 17 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts