Options
All
  • Public
  • Public/Protected
  • All
Menu

A default writer vended by a WritableStream.

Type parameters

  • W = any

Hierarchy

  • WritableStreamDefaultWriter

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

Readonly closed

closed: Promise<undefined>

Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or the writer’s lock is released before the stream finishes closing.

Readonly desiredSize

desiredSize: null | number

Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full. A producer can use this information to determine the right amount of data to write.

It will be null if the stream cannot be successfully written to (due to either being errored, or having an abort queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when the writer’s lock is released.

Readonly ready

ready: Promise<undefined>

Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips back to zero or below, the getter will return a new promise that stays pending until the next transition.

If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become rejected.

Methods

abort

  • abort(reason?: any): Promise<undefined>
  • If the reader is active, behaves the same as stream.abort(reason).

    Parameters

    • Optional reason: any

    Returns Promise<undefined>

close

  • close(): Promise<undefined>
  • If the reader is active, behaves the same as stream.close().

    Returns Promise<undefined>

releaseLock

  • releaseLock(): void
  • Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active. If the associated stream is errored when the lock is released, the writer will appear errored in the same way from now on; otherwise, the writer will appear closed.

    Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the promises returned from previous calls to write() have not yet settled). It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents other producers from writing in an interleaved manner.

    Returns void

write

  • write(chunk: W): Promise<undefined>
  • Writes the given chunk to the writable stream, by waiting until any previous writes have finished successfully, and then sending the chunk to the underlying sink's write() method. It will return a promise that fulfills with undefined upon a successful write, or rejects if the write fails or stream becomes errored before the writing process is initiated.

    Note that what "success" means is up to the underlying sink; it might indicate simply that the chunk has been accepted, and not necessarily that it is safely saved to its ultimate destination.

    Parameters

    • chunk: W

    Returns Promise<undefined>

Generated using TypeDoc