MultiblockWriter#
- class lsst.pipe.base.quantum_graph.MultiblockWriter(stream: ~typing.IO[bytes], int_size: int, file_size: int = 0, addresses: dict[~uuid.UUID, ~lsst.pipe.base.quantum_graph._multiblock.Address] = <factory>)#
Bases:
objectA helper object for writing multi-block files.
Attributes Summary
Running map of all addresses added to the file so far.
Running size of the full file.
Number of bytes to use for all integers.
A binary file-like object to write to.
Methods Summary
open_in_zip(zf, name, int_size[, use_tempfile])Open a writer for a file in a zip archive.
write_bytes(id, data)Write raw bytes to the multi-block file.
write_model(id, model, compressor)Write raw bytes to the multi-block file.
Attributes Documentation
- addresses: dict[UUID, Address] = <dataclasses._MISSING_TYPE object>#
Running map of all addresses added to the file so far.
When the multi-block file is fully written, this is appended to the
AddressWriter.addressesto write the corresponding address file.
- file_size: int = 0#
Running size of the full file.
- int_size: int = <dataclasses._MISSING_TYPE object>#
Number of bytes to use for all integers.
- stream: IO[bytes] = <dataclasses._MISSING_TYPE object>#
A binary file-like object to write to.
Methods Documentation
- classmethod open_in_zip(zf: zipfile.ZipFile, name: str, int_size: int, use_tempfile: bool = False) Iterator[MultiblockWriter]#
Open a writer for a file in a zip archive.
Parameters#
- zf
zipfile.ZipFile Zip archive to add the file to.
- name
str Base name for the multi-block file; an extension will be added.
- int_size
int Number of bytes to use for all integers.
- use_tempfile
bool, optional If
True, send writes to a temporary file and only add the file to the zip archive when the context manager closes. This involves more overall I/O, but it permits multiple multi-block files to be open for writing in the same zip archive at once.
Returns#
- writer
contextlib.AbstractContextManager[MultiblockWriter] Context manager that returns a writer when entered.
- zf
- write_bytes(id: UUID, data: bytes) Address#
Write raw bytes to the multi-block file.
Parameters#
- id
uuid.UUID Unique ID of the object described by this block.
- data
bytes Data to store directly.
Returns#
- address
Address Address of the bytes just written.
- id
- write_model(id: UUID, model: BaseModel, compressor: Compressor) Address#
Write raw bytes to the multi-block file.
Parameters#
- id
uuid.UUID Unique ID of the object described by this block.
- model
pydantic.BaseModel Model to convert to JSON and compress.
- compressor
Compressor Object with a
compressmethod that takes and returnsbytes.
Returns#
- address
Address Address of the bytes just written.
- id