Skip to content

HttpRangeReader

Defined in: io/http-reader.ts:49

A RandomAccessReader over an HTTP(S) URL using Range requests.

The result of a read is assembled from the bytes actually fetched, so it is correct regardless of cache eviction; the LRU page cache is purely an optimization for overlapping reads. A short 206 is followed up until the requested range is satisfied. End of file is concluded only from the known size or a 416, never from a cache miss. A server that never honors Range (a 200 to the initial probe) is read whole, once. After the probe succeeds with 206, a later full-body 200 throws rather than mixing two representations. Detecting a mid-read change needs a server validator (ETag/Last-Modified, replayed as If-Range); with none, a resource that changes but keeps answering 206 is not detected.

The page cache is best-effort: two concurrent reads missing the same page may each fetch it. When the total size is unknown a read allocates the caller-supplied length up front, so callers pass bounded lengths. A failed initial probe is sticky: every later read rethrows it, by design (a dead URL is not re-hammered); build a new reader to retry.

const reader = new HttpRangeReader("https://example.org/image.fits");
const header = await reader.read(0, 2880);
new HttpRangeReader(_url, options?): HttpRangeReader;

Defined in: io/http-reader.ts:65

Parameter Type
_url string | URL
options HttpRangeReaderOptions

HttpRangeReader

get size(): number | undefined;

Defined in: io/http-reader.ts:85

Total length in bytes, or undefined if the source size is unknown.

number | undefined

Total length in bytes, or undefined if the source size is unknown.

RandomAccessReader.size

read(offset, length): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: io/http-reader.ts:284

Parameter Type
offset number
length number

Promise<Uint8Array<ArrayBufferLike>>

RandomAccessReader.read