Skip to main content
Module

std/node/stream.ts>Duplex

Deno standard library
Go to Latest
class Duplex
implements Writable
extends Readable
import { Duplex } from "https://deno.land/std@0.145.0/node/stream.ts";

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 false.

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
writable: boolean
readonly
optional
writableBuffer: Buffered[]
readonly
writableCorked: number
readonly
writableEnded: boolean
readonly
writableFinished: boolean
readonly
writableHighWaterMark: number
readonly
writableLength: number
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
optional
_writev(chunks: Array<{ chunk: any; encoding: BufferEncoding; }>, callback: (error?: Error | null) => void): void
cork(): void
end(cb?: () => void): void
end(chunk: any, cb?: () => void): void
end(
chunk: any,
encoding?: BufferEncoding,
cb?: () => void,
): void
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:
| Blob
| 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.