Barecat#
- class barecat.Barecat(path, shard_size_limit=None, readonly=True, overwrite=False, auto_codec=False, exist_ok=True, append_only=False, threadsafe=False, allow_writing_symlinked_shard=False)#
Bases:
collections.abc.MutableMapping
[str
,Any
]Object for reading or writing a Barecat archive.
A Barecat archive consists of several (large) shard files, each containing the data of multiple small files, and an SQLite index database that maps file paths to the corresponding shard, offset and size within the shard, as well as metadata such as modification time and checksum.
The
Barecat
object provides two main interfaces:A dict-like interface, where keys are file paths and values are the file contents. The contents can be raw bytes, or automatically decoded based on the file extension, if
auto_codec
is set toTrue
or codecs have been registered viaregister_codec()
.A filesystem-like interface consisting of methods such as
open()
,exists()
,listdir()
,walk()
,glob()
, etc., modeled after Python’sos
module.
- Parameters:
path (str) – Path to the Barecat archive, without the -sqlite-index or -shard-XXXXX suffixes.
shard_size_limit (Optional[int]) – Maximum size of each shard file. If None, the shard size is unlimited.
readonly (bool) – If True, the Barecat archive is opened in read-only mode.
overwrite (bool) – If True, the Barecat archive is first deleted if it already exists.
auto_codec (bool) – If True, automatically encode/decode files based on their extension.
exist_ok (bool) – If True, do not raise an error if the Barecat archive already exists.
append_only (bool) – If True, only allow appending to the Barecat archive.
threadsafe (bool) – If True, the Barecat archive is opened in thread-safe mode, where each thread or process will hold its own database connection and file handles for the shards.
allow_writing_symlinked_shard (bool) – If True, allow writing to a shard file that is a symlink. Setting it to False is recommended, since changing the contents of a symlinked shard will bring the original index database out of sync with the actual shard contents.
Properties#
The number of files in the archive. |
|
The number of directories in the archive. |
|
The total size of all files in the archive, in bytes. |
|
Total size of all shard files, as determined by seeking to the end of the shard files. |
|
Total size of all shard files, as determined by the file system's stat response. |
|
Total size of all files in the archive, as determined by the index database. |
|
Maximum size of each shard file. |
|
Index object to manipulate the metadata database of the Barecat archive. |
Methods#
|
Get the contents of a file in the Barecat archive. |
|
Get the contents of a file in the Barecat archive, with a default value if the file does |
|
Iterate over all files in the archive, yielding (path, content) pairs. |
|
Iterate over all file paths in the archive. |
|
Iterate over all file contents in the archive. |
|
Check if a file with the given path exists in the archive. |
|
Get the number of files in the archive. |
|
Iterate over all file paths in the archive. |
|
Add a file to the Barecat archive. |
|
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D |
|
Remove a file from the Barecat archive. |
|
Open a file in the archive, as a file-like object. |
|
Check if a file or directory exists in the archive. |
|
Check if a file exists in the archive. |
|
Check if a directory exists in the archive. |
|
List all files and directories in a directory. |
|
Recursively list all files and directories in the tree starting from a directory. |
|
Iterate over all files and sub directories, as BarecatFileInfo or BarecatDirInfo |
|
Find all files and directories matching a Unix-like glob pattern. |
|
Find all files matching a Unix-like glob pattern. |
|
Iterate over all files and directories matching a Unix-like glob pattern. |
|
Iterate over all files matching a Unix-like glob pattern. |
|
Iterate over all file paths in the archive. |
|
Iterate over all directory paths in the archive. |
|
Read a file into a buffer, starting from an offset within the file. |
|
Read a file from the archive, starting from an offset and reading a specific number of |
|
Add a file or directory from the filesystem to the archive. |
|
Add a file or directory to the archive. |
|
Remove (delete) a file from the archive. |
|
Remove (delete) an empty directory from the archive. |
|
Remove (delete) a directory and all its contents recursively from the archive. |
|
Rename a file or directory in the archive. |
|
Merge the contents of another Barecat archive into this one. |
|
Logical end of a shard, in bytes, that is the position after the last byte of the last |
|
Physical end of a shard, in bytes, that is the end seek position of the shard file. |
|
Check the CRC32C checksum of a file in the archive. |
|
Verify the integrity of the Barecat archive. |
|
Register an encoder and decoder for one or more file extensions. |
|
Defragment the Barecat archive. |
|
Close the Barecat archive. |
Enter a context manager. |
|
|
Exit a context manager. |