FileFormatter

class lsst.daf.butler.formatters.file.FileFormatter(fileDescriptor: FileDescriptor, *, dataId: DataCoordinate | None = None, writeParameters: Mapping[str, Any] | None = None, writeRecipes: Mapping[str, Any] | None = None, **kwargs: Any)

Bases: Formatter

Interface for reading and writing files on a POSIX file system.

Methods Summary

fromBytes(serializedDataset[, component])

Read serialized data into a Dataset or its component.

read([component])

Read data from a file.

toBytes(inMemoryDataset)

Serialize the Dataset to bytes based on formatter.

write(inMemoryDataset)

Write a Python object to a file.

Methods Documentation

fromBytes(serializedDataset: bytes, component: str | None = None) Any

Read serialized data into a Dataset or its component.

Parameters:
serializedDatasetbytes

Bytes object to unserialize.

componentstr, optional

Component to read from the Dataset. Only used if the StorageClass for reading differed from the StorageClass used to write the file.

Returns:
inMemoryDatasetobject

The requested data as a Python object. The type of object is controlled by the specific formatter.

Raises:
FormatterNotImplementedError

Formatter does not support reading from bytes.

read(component: str | None = None) Any

Read data from a file.

Parameters:
componentstr, optional

Component to read from the file. Only used if the StorageClass for reading differed from the StorageClass used to write the file.

Returns:
inMemoryDatasetobject

The requested data as a Python object. The type of object is controlled by the specific formatter.

Raises:
ValueError

Component requested but this file does not seem to be a concrete composite.

FormatterNotImplementedError

Formatter does not implement a method to read from files.

toBytes(inMemoryDataset: Any) bytes

Serialize the Dataset to bytes based on formatter.

Parameters:
inMemoryDatasetobject

Object to serialize.

Returns:
serializedDatasetbytes

Bytes representing the serialized dataset.

Raises:
FormatterNotImplementedError

Formatter does not support reading from bytes.

write(inMemoryDataset: Any) None

Write a Python object to a file.

Parameters:
inMemoryDatasetobject

The Python object to store.

Returns:
pathstr

The path where the primary file is stored within the datastore.