1. easy-transform-stream
Create a transform stream using await instead of callbacks
easy-transform-stream
Package: easy-transform-stream
Created by: sindresorhus
Last modified: Tue, 31 Oct 2023 21:15:56 GMT
Version: 1.0.1
License: MIT
Downloads: 114,628
Repository: https://github.com/sindresorhus/easy-transform-stream

Install

npm install easy-transform-stream
yarn add easy-transform-stream

easy-transform-stream

Create a transform stream using await instead of callbacks

The built-in stream.Transform constructor forces you to deal with a callback interface. It's much nicer to just be able to await and return a value.

This package can be thought of as a modern version of through2.

Install

 npm install easy-transform-stream

Usage

 import transformStream from 'easy-transform-stream';

const stream = transformStream(async chunk => {
	const newChunk = await modifyChunk(chunk);
	return newChunk;
});

API

easyTransformStream(transformer, flusher?)

easyTransformStream(options, transformer, flusher?)

transformer(chunk, encoding, stream)

Type: Async function

Receives each chunk and is expected to return a transformed chunk.

flusher(stream)

Type: Async generator function

Yield additional chunks at the end of the stream.

options

Type: object

Same as the options for stream.Transform, except for transform and flush.

  • get-stream - Get a stream as a string, buffer, or array

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code