Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bf9e709b7b | |||
| a21cd607d6 | |||
| 718a7f24ba | |||
| 741a606d00 | |||
| 7537d7fa37 |
@@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# stream-to-push-stream
|
# @push-stream-std/stream-to-push-stream
|
||||||
|
|
||||||
Convert native Node.js streams to push-stream source, sink, and duplex interfaces.
|
Convert native Node.js streams to push-stream source, sink, and duplex interfaces.
|
||||||
|
|
||||||
@@ -41,8 +41,7 @@ npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authTok
|
|||||||
npm install @push-stream-std/stream-to-push-stream
|
npm install @push-stream-std/stream-to-push-stream
|
||||||
```
|
```
|
||||||
|
|
||||||
## Description
|
## Why
|
||||||
|
|
||||||
Utilities for bridging between the Node.js `stream` module (Readable, Writable, Duplex) and the push-stream protocol. PushSource wraps a Readable, listening to `data`/`end`/`error` events and implementing `pipe()`, `resume()`, and `abort()`. PushSink wraps a Writable, translating `write()` calls to `writable.write()` with `drain`-based backpressure and `end()` to `writable.end()`. PushDuplex wraps a Duplex stream as a combined source/sink for bidirectional push-stream pipelines.
|
Utilities for bridging between the Node.js `stream` module (Readable, Writable, Duplex) and the push-stream protocol. PushSource wraps a Readable, listening to `data`/`end`/`error` events and implementing `pipe()`, `resume()`, and `abort()`. PushSink wraps a Writable, translating `write()` calls to `writable.write()` with `drain`-based backpressure and `end()` to `writable.end()`. PushDuplex wraps a Duplex stream as a combined source/sink for bidirectional push-stream pipelines.
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@@ -78,8 +77,5 @@ Tests cover readable-to-source data flow and end handling, writable-to-sink writ
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
Node.js 18 or later. ESM only.
|
Node.js 22 or later. ESM only.
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT
|
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import { Readable, Writable, Duplex } from 'stream';
|
import { Readable, Writable, Duplex } from 'stream';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stream-to-push-stream - Convert Node.js streams to push-streams
|
||||||
|
*
|
||||||
|
* Bridges Node.js Readable/Writable/Duplex streams into the push-stream protocol
|
||||||
|
* so they can be composed with `@push-stream-std/*` operators.
|
||||||
|
*/
|
||||||
|
|
||||||
class PushSource {
|
class PushSource {
|
||||||
constructor(readable) {
|
constructor(readable) {
|
||||||
this.readable = readable;
|
this.readable = readable;
|
||||||
@@ -223,6 +230,11 @@ class PushDuplex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap a Node.js Readable stream as a push-stream source.
|
||||||
|
* @param {import('stream').Readable} readableStream
|
||||||
|
* @returns {object} A push-stream source
|
||||||
|
*/
|
||||||
export function source(readableStream) {
|
export function source(readableStream) {
|
||||||
if (!(readableStream instanceof Readable)) {
|
if (!(readableStream instanceof Readable)) {
|
||||||
throw new Error('Expected a Node.js Readable stream');
|
throw new Error('Expected a Node.js Readable stream');
|
||||||
@@ -230,6 +242,11 @@ export function source(readableStream) {
|
|||||||
return new PushSource(readableStream);
|
return new PushSource(readableStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap a Node.js Writable stream as a push-stream sink.
|
||||||
|
* @param {import('stream').Writable} writableStream
|
||||||
|
* @returns {object} A push-stream sink
|
||||||
|
*/
|
||||||
export function sink(writableStream) {
|
export function sink(writableStream) {
|
||||||
if (!(writableStream instanceof Writable)) {
|
if (!(writableStream instanceof Writable)) {
|
||||||
throw new Error('Expected a Node.js Writable stream');
|
throw new Error('Expected a Node.js Writable stream');
|
||||||
@@ -237,6 +254,11 @@ export function sink(writableStream) {
|
|||||||
return new PushSink(writableStream);
|
return new PushSink(writableStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap a Node.js Duplex stream as a push-stream duplex (`{ source, sink }`).
|
||||||
|
* @param {import('stream').Duplex} duplexStream
|
||||||
|
* @returns {{source: object, sink: object}} Push-stream duplex
|
||||||
|
*/
|
||||||
export function duplex(duplexStream) {
|
export function duplex(duplexStream) {
|
||||||
if (!(duplexStream instanceof Duplex)) {
|
if (!(duplexStream instanceof Duplex)) {
|
||||||
throw new Error('Expected a Node.js Duplex stream');
|
throw new Error('Expected a Node.js Duplex stream');
|
||||||
|
|||||||
Generated
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "@push-stream-std/stream-to-push-stream",
|
||||||
|
"version": "1.0.3",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "@push-stream-std/stream-to-push-stream",
|
||||||
|
"version": "1.0.3",
|
||||||
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push-stream-std/stream-to-push-stream",
|
"name": "@push-stream-std/stream-to-push-stream",
|
||||||
"version": "1.0.1",
|
"version": "1.0.5",
|
||||||
"description": "Convert Node.js streams to push-streams",
|
"description": "Convert Node.js streams to push-streams",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
@@ -29,5 +29,9 @@
|
|||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/"
|
"registry": "https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://hub.kl1.tenere.ai/push-stream-std/stream-to-push-stream.git"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user