Storage¶
Shared by the client and server: MSFormat identifies a file's format, and
StorePlan decides where a transferred file lands on disk and whether it is
converted (store_as) on the way.
store
¶
Decide where and in what format a transferred file is stored on disk.
MSFormat
¶
Bases: StrEnum
An on-disk MS data format.
Members compare equal to their DownloadFormat string values.
Conversion
dataclass
¶
MszxExpansion
dataclass
¶
MszxExpansion(
src: Path, entries: tuple[str, ...], target: MSFormat
)
Writes every member of a multi-member .mszx into one directory.
Each spectra entry of src becomes <entry stem>.<ext> stored as
target (MSFormat.MSZ or MSFormat.MZML).
targets
cached
property
¶
Map each spectra entry to an output file name.
Raises ValueError for unsafe names, or if two entries map
to the same output name.
write
async
¶
Store every member in archive_dir.
Members are extracted into a uniquely named staging directory that is renamed to archive_dir only once all of them succeed, so a failure leaves no partial output behind and concurrent downloads never share staging files. Names are validated before anything is written.
StorePlan
dataclass
¶
How a file downloaded to dest ends up on disk.
source is the format of the downloaded bytes (or None if unknown)
and target the requested store_as format (or None to keep the
file as-is). Build one with for_download to also validate the
combination before any I/O.
conversion
property
¶
conversion: Conversion | None
The conversion needed, or None if the file is stored as-is.
final_dest
property
¶
The output path, with its extension adjusted for any conversion.
may_expand
property
¶
Whether a multi-member .mszx would be expanded into a directory.
for_download
classmethod
¶
for_download(
url: str, dest: Path, store_as: DownloadFormat | None
) -> StorePlan
Plan storage for url, failing fast on unsupported conversions.
for_upload
classmethod
¶
for_upload(
dest_dir: Path,
filename: str,
source: MSFormat | None,
store_as: MSFormat,
) -> StorePlan
Plan storage for an upload of filename into dest_dir.
source is the format the client declared, or None to infer it from filename. mzML is compressed on the wire, so anything but an .mszx archive arrives as MSZ. Archives are always kept as-is, whatever store_as says.
unique_part_path
¶
A part_path variant that concurrent writers never share.
Two uploads can target the same dest (e.g. run.msz and
run.mzML both arrive as run.msz), so each needs its own file.
finalize
async
¶
Move or convert the downloaded part file into its final form.
Returns the final destination, or the archive directory for a
multi-member .mszx.