Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.storage.http_range_reader

Seekable HTTP byte-range reader for efficient partial access to remote files.

This module provides a seekable file-like object backed by HTTP Range requests, enabling efficient random access to remote files (e.g., MCAP files on S3) without downloading the entire file.

Module Contents

HttpRangeReader

class roboto.storage.http_range_reader.HttpRangeReader(url, read_ahead_size=_READ_AHEAD_SIZE)#View Source

A seekable, buffered byte-range reader backed by an HTTP URL.

Uses HTTP range requests so only the requested byte ranges are fetched, allowing efficient partial access to remote files (e.g., reading just the MCAP summary/index section at the end of a file without downloading the full data payload).

Reads are satisfied from an in-memory sparse cache. HTTP requests are only issued on a cache miss, fetching READ_AHEAD_SIZE bytes at a time. Unlike a simple single-buffer approach, this cache retains all fetched regions, so seeking back to previously-read data doesn’t trigger re-fetches.

This class implements the IO[bytes] protocol methods needed by mcap.reader.

Uses urllib3 connection pooling to reuse HTTP connections across requests, reducing TCP handshake and TLS negotiation overhead.

Parameters

url str
read_ahead_size int

HttpRangeReader.close()

close()#View Source

Close the reader and release resources.

Return type

None

HttpRangeReader.prefetch_range()

prefetch_range(start, end)#View Source

Prefetch a byte range using parallel HTTP requests.

Byte spans already in the cache (e.g., placed there by the footer read-behind at open, which covers the whole file when it is small) are not re-fetched; only the uncovered gaps are requested.

Parameters

start int

Start byte offset (inclusive)

end int

End byte offset (inclusive)

Return type

None

HttpRangeReader.read()

read(size=-1)#View Source

Parameters

size int

Return type

bytes

HttpRangeReader.readable()

readable()#View Source

Return type

bool

HttpRangeReader.seek()

seek(offset, whence=0)#View Source

Parameters

offset int
whence int

Return type

int

HttpRangeReader.seekable()

seekable()#View Source

Return type

bool

Properties

HttpRangeReader.size

size int #

Get the total size of the remote file in bytes.

Return type: int

HttpRangeReader.tell()

tell()#View Source

Return type

int

HttpRangeReader.writable()

writable()#View Source

Return type

bool

as_io_bytes()

roboto.storage.http_range_reader.as_io_bytes(reader)#View Source

Cast an HttpRangeReader to typing.IO[bytes] for type-checking purposes.

Parameters

Return type

IO[bytes]

logger

roboto.storage.http_range_reader.logger#View Source

Was this page helpful?