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
このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

ReadableStream

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

Overview

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

Attributes

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

Methods

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

getReader

readable.getReader(options?: ReaderOptions): ReadableStreamDefaultReader | ReadableStreamBYOBReader;
The getReader() method creates a reader and locks the current stream until the reader calls the releaseLock() method.

Parameters

Parameter
Type
Required
Description
options
Yes
The configuration items for generating the reader.

ReaderOptions

The following table describes the parameters of the ReaderOptions object.
Parameter
Type
Required
Description
mode
string
No
Reader The type of the `reader`. Default value: undefined. Valid values:
undefined
Create a reader of the ReadableStreamDefaultReader type.
byob
Create a reader of the ReadableStreamBYOBReader type.

pipeThrough

readable.pipeThrough(transformStream: TransformStream, options?: PipeToOptions): ReadableStream;
The pipeThrough() method pipes the data of the current readable stream to the writable side of the transformStream and returns the readable side of the transformStream.
Note:
During the piping, the writable side of the current stream is locked.

Parameters

Parameter
Type
Required
Description
transformStream
Yes
The destination to which the current stream is piped.
options
Yes
The configuration items for piping the stream.

PipeToOptions

The following table describes the configuration items for piping the stream.
Parameter
Type
Required
Description
preventClose
boolean
No
If the value is true, the writable stream is not closed along with the readable stream.
preventAbort
boolean
No
If the value is true, the writable stream is not stopped when an exception occurs on the readable stream.
preventCancel
boolean
No
If the value is true, the writable stream is not closed when the readable stream is incorrect.
signal
No
If `signal` is stopped, ongoing pipe operations are stopped.

pipeTo

readable.pipeTo(destination: WritableStream, options?: PipeToOptions): Promise<void>;
The pipeTo() method pipes the current readable stream to the destination writable stream.
Note:
During the piping, the destination of the current stream is locked.

Parameters

Parameter
Type
Required
Description
destination
Yes
The writable stream.
options
Yes
The configuration items for piping the stream.

tee

readable.tee(): [ReadableStream, ReadableStream];
The tee() method tees the current readable stream and returns two independent branches.

cancel

readable.cancel(reason?: string): Promise<string>;
The cancel() method ends the current stream.

References