lazy_wheel module¶
lazy_wheel
is derived from pip’s wheel download code. It is really a seekable
file-like based on HTTP range requests, backed by a sparse temporary file. Each
read()
issues one or more HTTP range requests to the URL depending on how much
of the file has already been downloaded, while read()`s from already-fetched
portions of the file are fulfilled by the backing file.
ZIP archives have a directory at the end of the file giving the offset to each compressed member. We fetch the directory, and then the portion of the file containing the member or members of interest, for a maximum of 3 requests to retrieve any individual file in the archive.
Lazy ZIP over HTTP
- class conda_package_streaming.lazy_wheel.LazyConda(url: str, session: Session, chunk_size: int = 10240)¶
Bases:
LazyZipOverHTTP
- prefetch(conda_file_id)¶
Conda fork specific. Prefetch the .info range from the remote archive. Reduces number of Range requests to 2 or 3 (1 or 2 for the directory, 1 for the file).
conda_file_id: name of .conda without path or .conda extension
- class conda_package_streaming.lazy_wheel.LazyZipOverHTTP(url: str, session: Session, chunk_size: int = 10240)¶
Bases:
object
File-like object mapped to a ZIP file over HTTP.
This uses HTTP range requests to lazily fetch the file’s content, which is supposed to be fed to ZipFile. If such requests are not supported by the server, raise HTTPRangeRequestUnsupported during initialization.
- read(size: int = -1) bytes ¶
Read up to size bytes from the object and return them.
As a convenience, if size is unspecified or -1, all bytes until EOF are returned. Fewer than size bytes may be returned if EOF is reached.
- seek(offset: int, whence: int = 0) int ¶
Change stream position and return the new absolute position.
Seek to offset relative position indicated by whence: * 0: Start of stream (the default). pos should be >= 0; * 1: Current position - pos may be negative; * 2: End of stream - pos usually negative.