add#

barecat.Barecat.add(info, *, data=None, fileobj=None, bufsize=shutil.COPY_BUFSIZE, dir_exist_ok=False)#

Add a file or directory to the archive.

Parameters:
  • info (BarecatEntryInfo) – BarecatFileInfo or BarecatDirInfo object to add.

  • 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).

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_ok is True and the item is a directory.

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))