Elide exporte Readable, Writable, Duplex, Transform et PassThrough.
L’exemple vérifié ci-dessous couvre Readable.from, des hooks Transform et
Writable personnalisés et l’achèvement d’un pipeline à base de Promise.
Exemple de pipeline
Utilisez node:stream/promises lorsque vous attendez pipeline :
import { Readable, Transform, Writable } from "node:stream";
import { pipeline } from "node:stream/promises";
const output = [];
const source = Readable.from(["a", "b"]);
const upper = new Transform({
transform(chunk, _encoding, callback) {
callback(null, String(chunk).toUpperCase());
},
});
const sink = new Writable({
write(chunk, _encoding, callback) {
output.push(String(chunk));
callback();
},
});
await pipeline(source, upper, sink);
console.log(output.join("")); // ABpipeline et finished de node:stream utilisent des signatures à callbacks.
Leurs formes renvoyant des Promise sont exportées par node:stream/promises.
Surface supplémentaire
Readable.from,Readable.wrapet l’itération asynchrone- des consommateurs à Promise tels que
toArray,forEach,some,every,findetreduce - des transformateurs de flux tels que
map,filter,flatMap,dropettake compose,addAbortSignal, des prédicats d’état et des utilitaires de high-water marknode:stream/iter, une extension Elide fournissant des utilitaires de conversion d’itérateurs
Consultez la documentation stream de Node.js pour les signatures standard des classes et des hooks.
Reference
Status: Partial · 215 of 238 suite tests pass (90.3%) · since 1.1.0
Exports
| Export | Kind | Status | Notes |
|---|---|---|---|
Readable | class | Full | readable, readableEnded, readableFlowing, readableHighWaterMark, readableLength, readableObjectMode, readableEncoding, destroyed, read(), setEncoding(), pause(), resume(), isPaused(), unpipe(), unshift(), wrap(), push(), destroy(), pipe(), toArray(), forEach(), some(), every(), find(), reduce(), map(), filter(), flatMap(), drop(), take() |
Writable | class | Full | writable, writableEnded, writableFinished, writableHighWaterMark, writableLength, writableObjectMode, writableCorked, destroyed, write(), end(), cork(), uncork(), destroy(), setDefaultEncoding() |
Duplex | class | Full | writable, writableEnded, writableFinished, writableHighWaterMark, writableLength, writableObjectMode, writableCorked, write(), end(), cork(), uncork(), setDefaultEncoding() |
Transform | class | Full | |
PassThrough | class | Full | |
Readable | property | Full | The Readable stream class |
Writable | property | Full | The Writable stream class |
Duplex | property | Full | The Duplex stream class |
Transform | property | Full | The Transform stream class |
PassThrough | property | Full | The PassThrough stream class |
pipeline | property | Full | Promise-based pipeline() utility for composing stream pipelines with error propagation |
finished | property | Full | Promise-based finished() utility that resolves/rejects when a stream completes or errors |
compose | property | Full | Composes streams into a single Duplex; pipes them and returns a Duplex that writes to the head and reads… |
Not implemented
stream/web.ReadableStreamTee.
Tests: node-api node:streams: 215 pass, 22 fail, 1 error, 9 skipped. Failing: test-stream-auto-destroy.js, test-stream-compose.js, test-stream-consumers.js, test-stream-destroy.js, test-stream-duplex-from.js, test-stream-duplex.js, test-stream-iter-disabled.js, test-stream-iter-readable-interop-disabled.js, and 15 more.