GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — WritableStream - Web APIs | MDN

WritableStream

Baseline
Widely available
*

This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2022.

* Some parts of this feature may have varying levels of support.

  • See full compatibility
  • Learn more

Note: This feature is available in Web Workers.

The WritableStream interface of the Streams API provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in backpressure and queuing.

WritableStream is a transferable object.

Constructor

WritableStream()

Creates a new WritableStream object.

Instance properties

WritableStream.locked Read only

A boolean indicating whether the WritableStream is locked to a writer.

Instance methods

WritableStream.abort()

Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be immediately moved to an error state, with any queued writes discarded.

WritableStream.close()

Closes the stream.

WritableStream.getWriter()

Returns a new instance of WritableStreamDefaultWriter and locks the stream to that instance. While the stream is locked, no other writer can be acquired until this one is released.

Examples

The following example illustrates several features of this interface. It creates the WritableStream with a custom sink. It then calls the stream's getWriter() method, which returns an instance of WritableStreamDefaultWriter. Next, several strings are written to the stream. Finally, close() returns a promise that resolves when all the writes have successfully completed.

js
const writableStream = new WritableStream(
  // Implement the sink
  {
    write(chunk) {
      const textElement = document.getElementById("text-output");
      textElement.textContent += chunk;
    },
  },
);

const writer = writableStream.getWriter();

try {
  writer.write("Hello, ");
  writer.write("world!\n");
  writer.write("This has been a demo!\n");

  await writer.close(); // wait for all chunks to be written
  console.log("All chunks written");
} catch (error) {
  console.error("Stream error: ", error);
}

This example does not support the backpressure feature of Streams.

Specifications

Specification
Streams
# ws-class

Browser compatibility

See also

  • Streams—The Definitive Guide

Help improve MDN

Learn how to contribute

This page was last modified on Jul 3, 2025 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.