open#

barecat.io.fileobj.BarecatFileObjectHelper.open(item, mode='r', encoding=None, errors=None, newline=None)[source]#

Open a file in the archive, as a file-like object.

Parameters:
  • item (Union[barecat.core.types.BarecatFileInfo, str]) – Either a BarecatFileInfo object, or a path to a file within the archive.

  • mode (str) – Mode to open the file in. ‘r’/’rt’/’rb’ - read only, file must exist ‘r+’/’r+b’ - read/write, file must exist ‘w’/’wt’/’wb’ - write, truncate if exists, create if not ‘w+’/’w+b’ - read/write, truncate if exists, create if not ‘x’/’xb’ - exclusive create, fail if exists ‘x+’/’x+b’ - exclusive create read/write, fail if exists ‘a’/’ab’ - append, create if not exists ‘a+’/’a+b’ - append read/write, create if not exists

  • encoding (Optional[str]) – Text encoding (only for text mode, default ‘utf-8’).

  • errors (Optional[str]) – Error handling for encoding (only for text mode).

  • newline (Optional[str]) – Newline handling (only for text mode).

Returns:

File-like object representing the file. Returns TextIOWrapper for text mode, BarecatFileObject for binary mode.

Raises:
Return type:

Union[BarecatFileObject, TextIOWrapper]