Skip to content
Class

UrlSource

A source backed by a URL. This is useful for reading data from the network. Requests will be made using an optimized reading and prefetching pattern to minimize request count and latency.

Extends: Source

Constructor

ts
constructor(
	url: string | URL,
	options: UrlSourceOptions = {},
): UrlSource;

Creates a new UrlSource backed by the resource at the specified URL.

See UrlSourceOptions.

Events

onread

ts
onread: ((start: number, end: number) => unknown) | null;

Called each time data is retrieved from the source. Will be called with the retrieved range (end exclusive).

Methods

getSizeOrNull()

ts
getSizeOrNull(): Promise<number | null>;

Resolves with the total size of the file in bytes. This function is memoized, meaning only the first call will retrieve the size.

Returns null if the source is unsized.

getSize()

ts
getSize(): Promise<number>;

Resolves with the total size of the file in bytes. This function is memoized, meaning only the first call will retrieve the size.

Throws an error if the source is unsized.

Released under the Mozilla Public License 2.0.