Skip to main content

ScheduledReadableFile

ScheduledReadableFile wraps a ReadableFile and schedules its byte-range reads. Concurrent reads of nearby ranges can share one underlying transfer. Each caller receives a standalone buffer containing its requested bytes. The wrapper has no cache of completed reads.

Usage with HttpFile​

On a high-latency object store, issue nearby reads together so the scheduler can combine them. Keep the underlying HttpFile for exact reads, such as metadata at opposite ends of a file. Both paths use the same pinned object identity and transport telemetry.

import {
HttpFile,
RangeRequestScheduler,
ScheduledReadableFile
} from '@loaders.gl/core/loader-utils';

const scheduler = new RangeRequestScheduler({
coalesceDelayMs: 0,
coalesceMaxGapBytes: 16_384,
maxConcurrency: 4
});
const file = await HttpFile.open('https://example.com/data.bin', {consistency: 'strict'});
const scheduled = new ScheduledReadableFile(file, {scheduler});

try {
const [header, trailer] = await Promise.all([
file.read(0, 4),
file.read(file.size - 8, 8)
]);

// For an object of at least 36 KiB, these nearby reads can share one HTTP request.
const [first, second] = await Promise.all([
scheduled.read(16_384, 4_096),
scheduled.read(32_768, 4_096)
]);
} finally {
await scheduled.close();
}

Choose a gap size that balances request latency against extra bytes transferred. Exact reads through file bypass the scheduler's concurrency budget. The scheduler's merged-range limits are described in the RangeRequestScheduler reference.

Constructor​

new ScheduledReadableFile(file, {scheduler?})

  • Pass a RangeRequestScheduler instance to share a transfer budget across wrappers. Each wrapper has an independent request identity, so even two files at the same URL cannot coalesce.
  • Pass RangeRequestSchedulerProps as scheduler to configure a private scheduler. Omitting it creates a private scheduler with the standard range limits.

File access and ownership​

  • read(offset, length, signal?) schedules the logical range. Aborting a read cancels its wait. A merged transfer continues while another read in that transfer still needs it.
  • handle, url, size, bigsize, and stat() expose underlying file metadata. Open an HTTP file explicitly before using its size to calculate offsets.
  • close() cancels queued and active reads owned by this wrapper and closes the underlying file. Other wrappers using the same scheduler can continue reading. Use one owning wrapper per file.