add#
- barecat._api.Barecat.add(item, *, data=None, fileobj=None, bufsize=shutil.COPY_BUFSIZE, dir_exist_ok=False, file_exist_ok=False)[source]#
Add a file or directory to the archive.
Parent directories are automatically created if they don’t exist (like
mkdir -p).- Parameters:
item (Union[BarecatEntryInfo, str]) – BarecatFileInfo or BarecatDirInfo object to add or a target path for a file.
data (Optional[bytes]) – File content. If None, the data is read from the file object.
fileobj – File-like object to read the data from.
bufsize (int) – Buffer size to use when reading from the file object.
dir_exist_ok (bool) – If True, do not raise an error when adding a directory and that directory already exists in the archive (as a directory).
file_exist_ok (bool) – If True, skip adding a file if a file with the same path already exists in the archive. This is useful for merge operations.
- Raises:
ValueError – If the file is larger than the shard size limit.
FileExistsBarecatError – If a file or directory with the same path already exists in the archive, unless
dir_exist_okis True and the item is a directory, orfile_exist_okis True and the item is a file.NotADirectoryBarecatError – If a parent path exists as a file.
Examples
>>> bc = Barecat('test.barecat', readonly=False) >>> bc.add(BarecatFileInfo(path='file.txt', mode=0o666), data=b'Hello, world!') >>> bc.add(BarecatDirInfo(path='dir', mode=0o777))