vis4d.data.io.zip¶
Zip data backend.
This backend works with filepaths pointing to valid Zip files. We assume that the given Zip file contains the whole dataset associated to this backend.
Classes
Backend for loading data from Zip files. |
- class ZipBackend[source]¶
Backend for loading data from Zip files.
This backend works with filepaths pointing to valid Zip files. We assume that the given Zip file contains the whole dataset associated to this backend.
Creates an instance of the class.
- exists(filepath)[source]¶
Check if filepath exists.
- Parameters:
filepath (str) – Path to file.
- Returns:
True if file exists, False otherwise.
- Return type:
bool
- get(filepath)[source]¶
Get values according to the filepath as bytes.
- Parameters:
filepath (str) – The path to the file. It consists of an Zip path together with the relative path inside it, e.g.: “/path/to/ file.zip/key/subkey/data”. If no .zip given inside filepath, the function will search for the first .zip file present in the path, i.e. “/path/to/file/key/subkey/data” will also /key/ subkey/data from /path/to/file.zip.
- Raises:
ZipFileNotFoundError – If no suitable file exists.
OSError – If the file cannot be opened.
ValueError – If key not found inside zip file.
- Returns:
The file content in bytes
- Return type:
bytes
- isfile(filepath)[source]¶
Check if filepath is a file.
- Parameters:
filepath (str) – Path to file.
- Returns:
True if file exists, False otherwise.
- Return type:
bool
- listdir(filepath)[source]¶
List all files in the given directory.
- Parameters:
filepath (str) – The path to the directory.
- Returns:
List of all files in the given directory.
- Return type:
list[str]
- set(filepath, content, mode='w')[source]¶
Write the file content to the zip file.
- Parameters:
filepath (
str
) – path/to/file.zip/key1/key2/key3content (
bytes
) – Bytes to be written to entry key3 within group key2 within another group key1, for example.mode (
Literal
['w'
,'a'
]) – Mode to open the file in. “w” for writing a file, “a” for appending to existing file.
- Raises:
ValueError – If filepath is not a valid .zip file
NotImplementedError – If the method is not implemented.
- Return type:
None