Functions
save_compressed
Save data as compressed JSON (.json.zst).
save_compressed
def save_compressed(data: dict[str, Any], path: Path, level: int = COMPRESSION_LEVEL) -> int
Save data as compressed JSON (.json.zst).
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
data |
dict[str, Any] |
— | Dictionary to serialize |
path |
Path |
— | Output path (should end in .json.zst) |
level |
int |
COMPRESSION_LEVEL |
Compression level 1-22 (default: 3) |
Returns
Number of bytes written (compressed size)int
—
load_compressed
Load compressed JSON (.json.zst).
load_compressed
def load_compressed(path: Path) -> dict[str, Any]
Load compressed JSON (.json.zst).
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
path |
Path |
— | Path to compressed cache file |
Returns
Deserialized dictionarydict[str, Any]
—
detect_format
Detect cache file format by extension.
detect_format
def detect_format(path: Path) -> str
Detect cache file format by extension.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
path |
Path |
— | Path to cache file |
Returns
"zstd" for .json.zst files, "json" for .json files, "unknown" otherwisestr
—
get_compressed_path
Get the compressed path for a JSON cache file.
get_compressed_path
def get_compressed_path(json_path: Path) -> Path
Get the compressed path for a JSON cache file.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
json_path |
Path |
— | Original JSON path (e.g., .bengal/cache.json) |
Returns
Compressed path (e.g., .bengal/cache.json.zst)Path
—
get_json_path
Get the JSON path for a compressed cache file.
get_json_path
def get_json_path(compressed_path: Path) -> Path
Get the JSON path for a compressed cache file.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
compressed_path |
Path |
— | Compressed path (e.g., .bengal/cache.json.zst) |
Returns
JSON path (e.g., .bengal/cache.json)Path
—
load_auto
Load cache file with automatic format detection.
Tries compressed format first (.json.zst), falls …
load_auto
def load_auto(path: Path) -> dict[str, Any]
Load cache file with automatic format detection.
Tries compressed format first (.json.zst), falls back to JSON (.json). This enables seamless migration from uncompressed to compressed caches.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
path |
Path |
— | Base path (without .zst extension) |
Returns
Deserialized dictionarydict[str, Any]
—
migrate_to_compressed
Migrate an uncompressed JSON cache file to compressed format.
migrate_to_compressed
def migrate_to_compressed(json_path: Path, remove_original: bool = True) -> Path | None
Migrate an uncompressed JSON cache file to compressed format.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
json_path |
Path |
— | Path to uncompressed JSON file |
remove_original |
bool |
True |
Whether to remove the original JSON file after migration |
Returns
Path to compressed file, or None if migration failed/not neededPath | None
—