WritableStream.WritableStream()

Draft
This page is not complete.

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The WritableStream() constructor creates a new WritableStream object instance.

Syntax

var writableStream = new WritableStream(underlyingSource[, queueingStrategy]);

Parameters

underlyingSink
An object containing methods and properties that define how the constructed stream instance will behave. underlyingSink can contain the following:
start(controller)
This is a method, called immediately when the object is constructed. The contents of this method are defined by the developer, and should aim to get access to the underlying sink. If this process is to be done asynchronously, it can return a promise to signal success or failure. The controller parameter passed to this method is a WritableStreamDefaultController. This can be used by the developer to control the stream during set up.
write(chunk, controller) Optional
This method, also defined by the developer, will be called when a new chunk of data (specified in the chunk parameter) is ready to be written to the underlying sink. It can return a promise to signal success or failure of the write operation. The controller parameter passed to this method is a WritableStreamDefaultController that can be used by the developer to control the stream as more chunks are submitted for writing. This method will be called only after previous writes have succeeded, and never after the stream is closed or aborted (see below).
close(controller) Optional
This method, also defined by the developer, will be called if the app signals that it has finished writing chunks to the stream. The contents should do whatever is necessary to finalize writes to the underlying sink, and release access to it. If this process is asynchronous, it can return a promise to signal success or failure. This method will be called only after all queued-up writes have succeeded. The controller parameter passed to this method is a WritableStreamDefaultController, which can be used to control the stream at the end of writing.
abort(reason) Optional
This method, also defined by the developer, will be called if the app signals that it wishes to abruptly close the stream and put it in an errored state. It can clean up any held resources, much like close(), but abort() will be called even if writes are queued up — those chunks will be thrown away. If this process is asynchronous, it can return a promise to signal success or failure. The reason parameter contains a DOMString describing why the stream was aborted.
queueingStrategy Optional
An object that optionally defines a queueing strategy for the stream. This takes two parameters:
highWaterMark
A non-negative integer — this defines the total number of chunks that can be contained in the internal queue before backpressure is applied.
size(chunk)
A method containing a parameter chunk — this indicates the size to use for each chunk, in bytes.

Note: You could define your own custom queueingStrategy, or use an instance of ByteLengthQueueingStrategy or CountQueueingStrategy for this object value. If no queueingStrategy is supplied, the default used is the same as a CountQueuingStrategy with a high water mark of 1.

Return value

An instance of the WritableStream object.

Examples

TBD

Specifications

Specification Status Comment
Streams
The definition of 'WritableStream()' in that specification.
Living Standard Initial definition.

Browser compatibility

No compatibility data found. Please contribute data for "path.to.feature.NameOfTheConstructor" (depth: 1) to the MDN compatibility data repository.

Document Tags and Contributors

 Contributors to this page: chrisdavidmills
 Last updated by: chrisdavidmills,