class internal.Duplex
implements WritableBase
Usage in Deno
import { internal } from "node:stream";
Duplex streams are streams that implement both the Readable
and Writable
interfaces.
Examples of Duplex
streams include:
TCP sockets
zlib streams
crypto streams
new
Duplex(opts?: DuplexOptions)
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 existing
Duplex
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
_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:
- close
- data
- drain
- end
- error
- finish
- pause
- pipe
- readable
- resume
- 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: "readable"): boolean
emit(event: "resume"): 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: "readable",listener: () => void,): this
on(event: "resume",listener: () => 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: "readable",listener: () => void,): this
once(event: "resume",listener: () => 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
A utility method for creating duplex streams.
Stream
converts writable stream into writableDuplex
and readable stream toDuplex
.Blob
converts into readableDuplex
.string
converts into readableDuplex
.ArrayBuffer
converts into readableDuplex
.AsyncIterable
converts into a readableDuplex
. Cannot yieldnull
.AsyncGeneratorFunction
converts into a readable/writable transformDuplex
. Must take a sourceAsyncIterable
as first parameter. Cannot yieldnull
.AsyncFunction
converts into a writableDuplex
. Must return eithernull
orundefined
Object ({ writable, readable })
convertsreadable
andwritable
intoStream
and then combines them intoDuplex
where theDuplex
will write to thewritable
and read from thereadable
.Promise
converts into readableDuplex
. Valuenull
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
.