WritableStream DefaultWriter
A writer is used when you want to write directly to a WritableStream
, rather than piping data to it from a ReadableStream
. For example:
-
writer.desiredSize
int- The size needed to fill the stream’s internal queue, as an integer. Always returns 1, 0 (if the stream is closed), or
null
(if the stream has errors).
- The size needed to fill the stream’s internal queue, as an integer. Always returns 1, 0 (if the stream is closed), or
-
writer.closed
Promise<void>- A promise that indicates if the writer is closed. The promise is fulfilled when the writer stream is closed and rejected if there is an error in the stream.
-
abort(reasonstringoptional)
: Promise<void>- Aborts the stream. This method returns a promise that fulfills with a response
undefined
.reason
is an optional human-readable string indicating the reason for cancellation.reason
will be passed to the underlying sink’s abort algorithm. If this writable stream is one side of a TransformStream, then its abort algorithm causes the transform’s readable side to become errored withreason
.
- Aborts the stream. This method returns a promise that fulfills with a response
-
close()
: Promise<void>- Attempts to close the writer. Remaining writes finish processing before the writer is closed. This method returns a promise fulfilled with
undefined
if the writer successfully closes and processes the remaining writes, or rejected on any error.
- Attempts to close the writer. Remaining writes finish processing before the writer is closed. This method returns a promise fulfilled with
-
releaseLock()
: void- Releases the writer’s lock on the stream. Once released, the writer is no longer active. You can call this method before all pending
write(chunk)
calls are resolved. This allows you to queue awrite
operation, release the lock, and begin piping into the writable stream from another source, as shown in the example below.
- Releases the writer’s lock on the stream. Once released, the writer is no longer active. You can call this method before all pending
-
write(chunkany)
: Promise<void>- Writes a chunk of data to the writer and returns a promise that resolves if the operation succeeds.
- The underlying stream may accept fewer kinds of type than
any
, it will throw an exception when encountering an unexpected type.