Skip to main content
Module

x/stream_slicing/partial_reader.ts>PartialReader

Deno and Node.js library for working with web standard streams
Latest
class PartialReader
Abstract
import { PartialReader } from "https://deno.land/x/stream_slicing@v1.1.0/partial_reader.ts";

Methods

abstract
cancel(reason?: unknown): Promise<void>

Cancel the ReadableStream reader. This may cause any in-progress or future reads to throw an error or think that the end of the stream has been reached.

abstract
limitedRead(maxSize: number): Promise<ReadableStreamDefaultReadResult<Uint8Array>>

Equivalent to ReadableStreamDefaultReader.read except that a maximum size is provided, and if the underlying read() result is greater than the maximum size, then the extra data will be buffered for later.

readAmount(size: number): Promise<Uint8Array>

Reads and returns size bytes from the stream, or less if the stream ends.

readAmountStrict(size: number): Promise<Uint8Array>

Reads and returns exactly size bytes from the stream. Throws an error if the reader ends before filling the buffer.

skipAmount(size: number): Promise<void>

Skips size bytes of the stream. Uses PartialReaderOptions.seek to seek the stream if available, otherwise does it by reading bytes from the stream and ignoring the result.

Returns a ReadableStream that the underlying reader is redirected to for the next size bytes. If you want to assert that the returned stream outputs size bytes without ending early, then use .pipeThrough(new ExactBytesTransformStream(size)) on the result.

Static Methods

Construct a PartialReader from a ReadableStream.

Internally this will return a subclass of PartialReader based on whether the stream supports byob mode ("bring your own buffer") readers, which are more efficient for some use-cases.

If the stream is seekable, then pass a callback to PartialReaderOptions.seek to enable efficient seeking.