Skip to main content

Duplex

class default.Duplex
implements WritableBase
extends ReadableBase

Duplex streams are streams that implement both the Readable and Writable interfaces.

Examples of Duplex streams include:

  • TCP sockets
  • zlib streams
  • crypto streams

Constructors Jump to heading

Properties Jump to heading

If false then the stream will automatically end the writable side when the readable side ends. Set initially by the allowHalfOpen constructor option, which defaults to true.

This can be changed manually to change the half-open behavior of an existing Duplex stream instance, but must be changed before the 'end' event is emitted.

readonly
Jump to headingclosed: boolean
readonly
Jump to headingerrored: Error | null
readonly
Jump to headingwritable: boolean
Jump to heading_destroy(
error: Error | null,
callback: (error?: Error | null) => void,
): void
Jump to heading_final(callback: (error?: Error | null) => void): void
Jump to heading_write(
chunk: any,
encoding: BufferEncoding,
callback: (error?: Error | null) => void,
): void
optional
Jump to heading_writev(
chunks: Array<{ chunk: any; encoding: BufferEncoding; }>,
callback: (error?: Error | null) => void,
): void
Jump to headingaddListener(
event: "close",
listener: () => void,
): this

Event emitter The defined events on documents including:

  1. close
  2. data
  3. drain
  4. end
  5. error
  6. finish
  7. pause
  8. pipe
  9. readable
  10. resume
  11. unpipe
Jump to headingaddListener(
event: "data",
listener: (chunk: any) => void,
): this
Jump to headingaddListener(
event: "drain",
listener: () => void,
): this
Jump to headingaddListener(
event: "end",
listener: () => void,
): this
Jump to headingaddListener(
event: "error",
listener: (err: Error) => void,
): this
Jump to headingaddListener(
event: "finish",
listener: () => void,
): this
Jump to headingaddListener(
event: "pause",
listener: () => void,
): this
Jump to headingaddListener(
event: "pipe",
listener: (src: Readable) => void,
): this
Jump to headingaddListener(
event: "readable",
listener: () => void,
): this
Jump to headingaddListener(
event: "resume",
listener: () => void,
): this
Jump to headingaddListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
Jump to headingaddListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
Jump to headingemit(event: "close"): boolean
Jump to headingemit(
event: "data",
chunk: any,
): boolean
Jump to headingemit(event: "drain"): boolean
Jump to headingemit(event: "end"): boolean
Jump to headingemit(
event: "error",
err: Error,
): boolean
Jump to headingemit(event: "finish"): boolean
Jump to headingemit(event: "pause"): boolean
Jump to headingemit(
event: "pipe",
src: Readable,
): boolean
Jump to headingemit(event: "readable"): boolean
Jump to headingemit(event: "resume"): boolean
Jump to headingemit(
event: "unpipe",
src: Readable,
): boolean
Jump to headingemit(
event: string | symbol,
...args: any[],
): boolean
Jump to headingend(cb?: () => void): this
Jump to headingend(
chunk: any,
cb?: () => void,
): this
Jump to headingend(
chunk: any,
encoding?: BufferEncoding,
cb?: () => void,
): this
Jump to headingon(
event: "close",
listener: () => void,
): this
Jump to headingon(
event: "data",
listener: (chunk: any) => void,
): this
Jump to headingon(
event: "drain",
listener: () => void,
): this
Jump to headingon(
event: "end",
listener: () => void,
): this
Jump to headingon(
event: "error",
listener: (err: Error) => void,
): this
Jump to headingon(
event: "finish",
listener: () => void,
): this
Jump to headingon(
event: "pause",
listener: () => void,
): this
Jump to headingon(
event: "pipe",
listener: (src: Readable) => void,
): this
Jump to headingon(
event: "readable",
listener: () => void,
): this
Jump to headingon(
event: "resume",
listener: () => void,
): this
Jump to headingon(
event: "unpipe",
listener: (src: Readable) => void,
): this
Jump to headingon(
event: string | symbol,
listener: (...args: any[]) => void,
): this
Jump to headingonce(
event: "close",
listener: () => void,
): this
Jump to headingonce(
event: "data",
listener: (chunk: any) => void,
): this
Jump to headingonce(
event: "drain",
listener: () => void,
): this
Jump to headingonce(
event: "end",
listener: () => void,
): this
Jump to headingonce(
event: "error",
listener: (err: Error) => void,
): this
Jump to headingonce(
event: "finish",
listener: () => void,
): this
Jump to headingonce(
event: "pause",
listener: () => void,
): this
Jump to headingonce(
event: "pipe",
listener: (src: Readable) => void,
): this
Jump to headingonce(
event: "readable",
listener: () => void,
): this
Jump to headingonce(
event: "resume",
listener: () => void,
): this
Jump to headingonce(
event: "unpipe",
listener: (src: Readable) => void,
): this
Jump to headingonce(
event: string | symbol,
listener: (...args: any[]) => void,
): this
Jump to headingprependListener(
event: "close",
listener: () => void,
): this
Jump to headingprependListener(
event: "data",
listener: (chunk: any) => void,
): this
Jump to headingprependListener(
event: "drain",
listener: () => void,
): this
Jump to headingprependListener(
event: "end",
listener: () => void,
): this
Jump to headingprependListener(
event: "error",
listener: (err: Error) => void,
): this
Jump to headingprependListener(
event: "finish",
listener: () => void,
): this
Jump to headingprependListener(
event: "pause",
listener: () => void,
): this
Jump to headingprependListener(
event: "pipe",
listener: (src: Readable) => void,
): this
Jump to headingprependListener(
event: "readable",
listener: () => void,
): this
Jump to headingprependListener(
event: "resume",
listener: () => void,
): this
Jump to headingprependListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
Jump to headingprependListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
Jump to headingprependOnceListener(
event: "close",
listener: () => void,
): this
Jump to headingprependOnceListener(
event: "data",
listener: (chunk: any) => void,
): this
Jump to headingprependOnceListener(
event: "drain",
listener: () => void,
): this
Jump to headingprependOnceListener(
event: "end",
listener: () => void,
): this
Jump to headingprependOnceListener(
event: "error",
listener: (err: Error) => void,
): this
Jump to headingprependOnceListener(
event: "finish",
listener: () => void,
): this
Jump to headingprependOnceListener(
event: "pause",
listener: () => void,
): this
Jump to headingprependOnceListener(
event: "pipe",
listener: (src: Readable) => void,
): this
Jump to headingprependOnceListener(
event: "readable",
listener: () => void,
): this
Jump to headingprependOnceListener(
event: "resume",
listener: () => void,
): this
Jump to headingprependOnceListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
Jump to headingprependOnceListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
Jump to headingremoveListener(
event: "close",
listener: () => void,
): this
Jump to headingremoveListener(
event: "data",
listener: (chunk: any) => void,
): this
Jump to headingremoveListener(
event: "drain",
listener: () => void,
): this
Jump to headingremoveListener(
event: "end",
listener: () => void,
): this
Jump to headingremoveListener(
event: "error",
listener: (err: Error) => void,
): this
Jump to headingremoveListener(
event: "finish",
listener: () => void,
): this
Jump to headingremoveListener(
event: "pause",
listener: () => void,
): this
Jump to headingremoveListener(
event: "pipe",
listener: (src: Readable) => void,
): this
Jump to headingremoveListener(
event: "readable",
listener: () => void,
): this
Jump to headingremoveListener(
event: "resume",
listener: () => void,
): this
Jump to headingremoveListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
Jump to headingremoveListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
Jump to headingsetDefaultEncoding(encoding: BufferEncoding): this
Jump to headingwrite(
chunk: any,
encoding?: BufferEncoding,
cb?: (error:
Error
| null
| undefined
) => void
,
): boolean
Jump to headingwrite(
chunk: any,
cb?: (error:
Error
| null
| undefined
) => void
,
): boolean

Static Methods Jump to heading

Jump to headingfrom(src:
Stream
| NodeBlob
| ArrayBuffer
| string
| Iterable<any>
| AsyncIterable<any>
| AsyncGeneratorFunction
| Promise<any>
| Object
): Duplex

A utility method for creating duplex streams.

  • Stream converts writable stream into writable Duplex and readable stream to Duplex.
  • Blob converts into readable Duplex.
  • string converts into readable Duplex.
  • ArrayBuffer converts into readable Duplex.
  • AsyncIterable converts into a readable Duplex. Cannot yield null.
  • AsyncGeneratorFunction converts into a readable/writable transform Duplex. Must take a source AsyncIterable as first parameter. Cannot yield null.
  • AsyncFunction converts into a writable Duplex. Must return either null or undefined
  • Object ({ writable, readable }) converts readable and writable into Stream and then combines them into Duplex where the Duplex will write to the writable and read from the readable.
  • Promise converts into readable Duplex. Value null is ignored.
Jump to headingfromWeb(
duplexStream: { readable: streamWeb.ReadableStream; writable: streamWeb.WritableStream; },
options?: Pick<DuplexOptions,
"allowHalfOpen"
| "decodeStrings"
| "encoding"
| "highWaterMark"
| "objectMode"
| "signal"
>
,
): Duplex

A utility method for creating a Duplex from a web ReadableStream and WritableStream.

Jump to headingtoWeb(streamDuplex: Duplex): { readable: streamWeb.ReadableStream; writable: streamWeb.WritableStream; }

A utility method for creating a web ReadableStream and WritableStream from a Duplex.

Back to top