请选择
Edge Developer Platform
  • Edge Functions
    • Overview
    • Getting Started
    • Operation Guide
      • Function Management
      • Function Trigger
    • Runtime APIs
      • addEventListener
      • Cache
      • Cookies
      • Encoding
      • Fetch
      • FetchEvent
      • Headers
      • Request
      • Response
      • Streams
        • ReadableStream
        • ReadableStreamBYOBReader
        • ReadableStreamDefaultReader
        • TransformStream
        • WritableStream
        • WritableStreamDefaultWriter
      • Web Crypto
      • Web standards
      • Images
        • ImageProperties
    • Sample Functions
      • Returning an HTML Page
      • Returning a JSON Object
      • Fetch Remote Resources
      • Authenticating a Request Header
      • Modifying a Response Header
      • Performing an A/B Test
      • Setting Cookies
      • Performing Redirect Based on the Request Location
      • Using the Cache API
      • Caching POST Requests
      • Responding in Streaming Mode
      • Merging Resources and Responding in Streaming Mode
      • Protecting Data from Tampering
      • Rewriting a m3u8 File and Configuring Authentication
      • Adaptive Image Resize
      • Image Adaptive WebP
      • Customize Referer restriction rules
      • Remote Authentication
      • HMAC Digital Signature
      • Naming a Downloaded File
      • Obtaining Client IP Address
    • Best Practices
      • Adaptive Image Format Conversion via Edge Functions

WritableStreamDefaultWriter

The WritableStreamDefaultWriter API defines a writer for a writable stream. It is designed based on the standard Web API WritableStreamDefaultWriter.
Note:
A WritableStreamDefaultWriter object cannot be constructed directly. You can use the WritableStream.getWriter method to construct a WritableStreamDefaultWriter object.

Overview

// Use TransformStream to construct a WritableStream object.
const { writable } = new TransformStream();

// Use the WritableStream object to obtain the writer.
const writer = writable.getWriter();

Attributes

closed

// writer.closed
readonly closed: Promise<void>;
The closed attribute returns a Promise object. If the stream is closed, the status of the Promise object is fulfilled. If an exception occurs on the lock on the writer is released, the status of the Promise object is rejected.

ready

// writer.ready
readonly ready: Promise<void>;
The ready attribute returns a Promise object. When the size required by the internal queue of the stream changes from non-positive to positive, the Promise object is in the fulfilled status, indicating that it no longer applies backpressure.

desiredSize

// writer.desiredSize
readonly desiredSize: number;
The desiredSize attribute returns the size required to fill the internal queue of the stream.

Methods

write

writer.write(chunk: Chunk): Promise<void>;
The write() method writes the Chunk data to the stream.
Note:
You cannot call the write method to initiate the next stream writing operation until the current stream writing operation ends.

Parameters

Parameter
Type
Required
Description
chunk
Yes
The chunk of data to be written to the stream.

Chunk

The Chunk parameter indicates the data to be written to the stream.
type Chunk = string | ArrayBuffer | ArrayBufferView;

close

writer.close(): Promise<void>;
The close() method closes the current stream.

abort

writer.abort(reason?: string): Promise<string>;
The abort() method stops the current stream.

releaseLock

writer.releaseLock(): void;
The releaseLock() method cancels the association with the stream and releases the lock on the stream.

References