internal.Duplex - Node documentation
class internal.Duplex
implements WritableBase
extends ReadableBase

Usage in Deno

import { internal } from "node:stream";
const { Duplex } = internal;

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

Examples of Duplex streams include:

  • TCP sockets
  • zlib streams
  • crypto streams

Constructors

new
Duplex(opts?: DuplexOptions)

Properties

allowHalfOpen: boolean

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 existingDuplex stream instance, but must be changed before the 'end' event is emitted.

readonly
closed: boolean
readonly
errored: Error | null
readonly
writable: boolean
readonly
writableCorked: number
readonly
writableEnded: boolean
readonly
writableFinished: boolean
readonly
writableHighWaterMark: number
readonly
writableLength: number
readonly
writableNeedDrain: boolean
readonly
writableObjectMode: boolean

Methods

_destroy(
error: Error | null,
callback: (error?: Error | null) => void,
): void
_final(callback: (error?: Error | null) => void): void
_write(
chunk: any,
encoding: BufferEncoding,
callback: (error?: Error | null) => void,
): void
abstract
_writev(
chunks: Array<{ chunk: any; encoding: BufferEncoding; }>,
callback: (error?: Error | null) => void,
): void
addListener(
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
addListener(
event: "data",
listener: (chunk: any) => void,
): this
addListener(
event: "drain",
listener: () => void,
): this
addListener(
event: "end",
listener: () => void,
): this
addListener(
event: "error",
listener: (err: Error) => void,
): this
addListener(
event: "finish",
listener: () => void,
): this
addListener(
event: "pause",
listener: () => void,
): this
addListener(
event: "pipe",
listener: (src: Readable) => void,
): this
addListener(
event: "readable",
listener: () => void,
): this
addListener(
event: "resume",
listener: () => void,
): this
addListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
addListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
cork(): void
emit(event: "close"): boolean
emit(
event: "data",
chunk: any,
): boolean
emit(event: "drain"): boolean
emit(event: "end"): boolean
emit(
event: "error",
err: Error,
): boolean
emit(event: "finish"): boolean
emit(event: "pause"): boolean
emit(
event: "pipe",
src: Readable,
): boolean
emit(event: "readable"): boolean
emit(event: "resume"): boolean
emit(
event: "unpipe",
src: Readable,
): boolean
emit(
event: string | symbol,
...args: any[],
): boolean
end(cb?: () => void): this
end(
chunk: any,
cb?: () => void,
): this
end(
chunk: any,
encoding?: BufferEncoding,
cb?: () => void,
): this
on(
event: "close",
listener: () => void,
): this
on(
event: "data",
listener: (chunk: any) => void,
): this
on(
event: "drain",
listener: () => void,
): this
on(
event: "end",
listener: () => void,
): this
on(
event: "error",
listener: (err: Error) => void,
): this
on(
event: "finish",
listener: () => void,
): this
on(
event: "pause",
listener: () => void,
): this
on(
event: "pipe",
listener: (src: Readable) => void,
): this
on(
event: "readable",
listener: () => void,
): this
on(
event: "resume",
listener: () => void,
): this
on(
event: "unpipe",
listener: (src: Readable) => void,
): this
on(
event: string | symbol,
listener: (...args: any[]) => void,
): this
once(
event: "close",
listener: () => void,
): this
once(
event: "data",
listener: (chunk: any) => void,
): this
once(
event: "drain",
listener: () => void,
): this
once(
event: "end",
listener: () => void,
): this
once(
event: "error",
listener: (err: Error) => void,
): this
once(
event: "finish",
listener: () => void,
): this
once(
event: "pause",
listener: () => void,
): this
once(
event: "pipe",
listener: (src: Readable) => void,
): this
once(
event: "readable",
listener: () => void,
): this
once(
event: "resume",
listener: () => void,
): this
once(
event: "unpipe",
listener: (src: Readable) => void,
): this
once(
event: string | symbol,
listener: (...args: any[]) => void,
): this
prependListener(
event: "close",
listener: () => void,
): this
prependListener(
event: "data",
listener: (chunk: any) => void,
): this
prependListener(
event: "drain",
listener: () => void,
): this
prependListener(
event: "end",
listener: () => void,
): this
prependListener(
event: "error",
listener: (err: Error) => void,
): this
prependListener(
event: "finish",
listener: () => void,
): this
prependListener(
event: "pause",
listener: () => void,
): this
prependListener(
event: "pipe",
listener: (src: Readable) => void,
): this
prependListener(
event: "readable",
listener: () => void,
): this
prependListener(
event: "resume",
listener: () => void,
): this
prependListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
prependListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
prependOnceListener(
event: "close",
listener: () => void,
): this
prependOnceListener(
event: "data",
listener: (chunk: any) => void,
): this
prependOnceListener(
event: "drain",
listener: () => void,
): this
prependOnceListener(
event: "end",
listener: () => void,
): this
prependOnceListener(
event: "error",
listener: (err: Error) => void,
): this
prependOnceListener(
event: "finish",
listener: () => void,
): this
prependOnceListener(
event: "pause",
listener: () => void,
): this
prependOnceListener(
event: "pipe",
listener: (src: Readable) => void,
): this
prependOnceListener(
event: "readable",
listener: () => void,
): this
prependOnceListener(
event: "resume",
listener: () => void,
): this
prependOnceListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
prependOnceListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
removeListener(
event: "close",
listener: () => void,
): this
removeListener(
event: "data",
listener: (chunk: any) => void,
): this
removeListener(
event: "drain",
listener: () => void,
): this
removeListener(
event: "end",
listener: () => void,
): this
removeListener(
event: "error",
listener: (err: Error) => void,
): this
removeListener(
event: "finish",
listener: () => void,
): this
removeListener(
event: "pause",
listener: () => void,
): this
removeListener(
event: "pipe",
listener: (src: Readable) => void,
): this
removeListener(
event: "readable",
listener: () => void,
): this
removeListener(
event: "resume",
listener: () => void,
): this
removeListener(
event: "unpipe",
listener: (src: Readable) => void,
): this
removeListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
setDefaultEncoding(encoding: BufferEncoding): this
uncork(): void
write(
chunk: any,
encoding?: BufferEncoding,
cb?: (error:
Error
| null
| undefined
) => void
,
): boolean
write(
chunk: any,
cb?: (error:
Error
| null
| undefined
) => void
,
): boolean

Static Methods

from(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.
fromWeb(
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.

toWeb(streamDuplex: Duplex): { readable: streamWeb.ReadableStream; writable: streamWeb.WritableStream; }

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