memory_file_map#
Classes
In-memory representation of a file archive |
- class kernelfoundry.eval_pipeline.utils.memory_file_map.MemoryFileMap[source]#
In-memory representation of a file archive
- open(file_path: str | Path, mode: str = 'r') BytesIO | TextIOWrapper[source]#
Opens a file in the archive with the specified mode.
- Parameters:
file_path (str | Path) – Path of the file within the archive.
mode (str) – Mode to open the file (‘r’, ‘w’, ‘rb’, ‘wb’). - ‘r’: Read text mode (returns TextIOWrapper) - ‘w’: Write text mode (returns TextIOWrapper) - ‘rb’: Read binary mode (returns BytesIO) - ‘wb’: Write binary mode (returns BytesIO)
- Returns:
The file stream in binary or text mode.
- Return type:
- Raises:
ValueError – If an invalid mode is provided.
FileNotFoundError – If the file doesn’t exist in read mode.
- remove_root_dir() bool[source]#
Removes a common root directory or directories from all files in the archive.
- Returns:
True if a common root directory was found and removed, False otherwise.
- Return type:
- to_tarball(mode='w:gz') bytes[source]#
Creates a tarball from the in-memory files.
- Returns:
The tarball as a byte string.
- Return type:
- from_tarball(*, tarball_bytes: bytes | None = None, tarball_path: Path | str | None = None)[source]#
Loads files from a tarball into the in-memory archive.
- from_zip(*, zip_bytes: bytes | None = None, zip_path: Path | str | None = None)[source]#
Loads files from a zip archive into the in-memory archive.
- from_archive(*, archive_bytes: bytes | None = None, archive_path: Path | str | None = None)[source]#
Loads files from an archive (zip or tarball) into the in-memory archive.
- from_path(path: str | Path, include_extensions: list[str] | None = None)[source]#
Loads files from a given path to an archive or directory into the in-memory archive.
- to_disk(output_dir: str | Path)[source]#
Extracts the archive to disk.
- Parameters:
output_dir (str | Path) – Directory where files will be extracted.
- from_disk(input_dir: str | Path, include_extensions: list[str] | None = None)[source]#
Loads files from disk into the in-memory archive.
- encode() dict[source]#
Encodes the archive to a serializable dictionary.
- Returns:
- Mapping of file path -> {“content”: base64 str, “mode”: int, “mtime”: float}.
mode/mtime are omitted for files with no recorded metadata.
- Return type:
- decode(encoded_map: dict)[source]#
Decodes a serializable dictionary into the archive.
Accepts both the current format (per-file dict with content/mode/mtime) and the legacy format (path -> base64 string) for backward compatibility.
- Parameters:
encoded_map (dict) – Mapping produced by
encode(new or legacy format).