Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

stream: add SyncTransform #61326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
mcollina wants to merge 1 commit into nodejs:main
base: main
Choose a base branch
Loading
from mcollina:stream-synctransform
Draft

Conversation

@mcollina
Copy link
Member

@mcollina mcollina commented Jan 9, 2026

Summary

Add SyncTransform, a high-performance synchronous transform stream based on the syncthrough npm package.

Unlike the standard Transform stream, SyncTransform uses a synchronous transformation function (no callback), which results in significantly better performance (~10x faster).

Key Features

  • Synchronous transform function for better performance
  • Strict backpressure enforcement without internal buffering
  • Works with pipeline(), pipe(), and 'data' events
  • Supports object mode automatically
  • Includes flush function for final data emission

Example

const { SyncTransform, pipeline } = require('node:stream');
const { createReadStream } = require('node:fs');
pipeline(
 createReadStream('input.txt'),
 SyncTransform((chunk) => chunk.toString().toUpperCase()),
 process.stdout,
 (err) => {
 if (err) console.error(err);
 }
);

Caveats

  1. Strict backpressure: Writing before piping buffers exactly one chunk
  2. Single destination: Only one pipe() destination allowed
  3. No readable event: Data pushed directly to destination
  4. Either pipe() or 'data': Cannot use both simultaneously
  5. Object mode by default: Handles objects without explicit configuration

Add SyncTransform, a high-performance synchronous transform stream
based on the syncthrough npm package. Unlike the standard Transform
stream, SyncTransform uses a synchronous transformation function
(no callback), which results in significantly better performance.
Key features:
- Synchronous transform function for ~10x better performance
- Strict backpressure enforcement without internal buffering
- Works with pipeline(), pipe(), and 'data' events
- Supports object mode automatically
- Includes flush function for final data emission
PR-URL: https://github.com/nodejs/node/pull/XXXXX 
Copy link
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. labels Jan 9, 2026
Copy link
Member

ronag commented Jan 9, 2026
edited
Loading

Awesome! But I have opinions... it's unfortunate that it tries to pretend to be a node stream even when it's clearly not.

I would prefer if it instead in some way was a construct for pipeline/compose. Something like:

pipeline(src, pipeline.map(chunk => chunk), dst, () => {})

The implementation could also be simpler then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /