请选择
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

WritableStream

The WritableStream API represents a writable stream or writable side. It is designed based on the standard Web API WritableStream.
Note:
A WritableStream object cannot be constructed directly. You can use TransformStream to construct a WritableStream object.

Overview

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

Attributes

locked

// writable.locked
readonly locked: boolean;
The locked attribute indicates whether the stream is locked.
Note:
A stream is locked in the following scenarios:
The stream has no more than one activated writer. Before the writer calls the releaseLock() method, the stream is locked.
The stream is in being piped. The stream is locked until the piping ends.

highWaterMark

// writable.highWaterMark
readonly highWaterMark: number;
The size of the writable buffer in bytes. Default value: 32K. Maximum value: 256K. If you enter a value greater than 256K, the value is changed to 256K automatically.

Methods

Note:
Before you use any of the following methods, make sure that the stream is not locked. Otherwise, an exception is returned.

getWriter

writable.getWriter(): WritableStreamDefaultWriter;
The getWriter() method creates a writer and locks the current stream until the writer calls the releaseLock() method. For more information about the returned values, see WritableStreamDefaultWriter.

close

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

abort

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

References