A file object providing transparent LZMA (de)compression. An LZMAFile can act as a wrapper for an existing file object, or refer directly to a named file on disk. Note that LZMAFile provides a *binary* file interface - data read is returned as bytes, and data to be written must be
| 36 | |
| 37 | |
| 38 | class LZMAFile(_streams.BaseStream): |
| 39 | |
| 40 | """A file object providing transparent LZMA (de)compression. |
| 41 | |
| 42 | An LZMAFile can act as a wrapper for an existing file object, or |
| 43 | refer directly to a named file on disk. |
| 44 | |
| 45 | Note that LZMAFile provides a *binary* file interface - data read |
| 46 | is returned as bytes, and data to be written must be given as bytes. |
| 47 | """ |
| 48 | |
| 49 | def __init__(self, filename=None, mode="r", *, |
| 50 | format=None, check=-1, preset=None, filters=None): |
| 51 | """Open an LZMA-compressed file in binary mode. |
| 52 | |
| 53 | filename can be either an actual file name (given as a str, |
| 54 | bytes, or PathLike object), in which case the named file is |
| 55 | opened, or it can be an existing file object to read from or |
| 56 | write to. |
| 57 | |
| 58 | mode can be "r" for reading (default), "w" for (over)writing, |
| 59 | "x" for creating exclusively, or "a" for appending. These can |
| 60 | equivalently be given as "rb", "wb", "xb" and "ab" respectively. |
| 61 | |
| 62 | format specifies the container format to use for the file. |
| 63 | If mode is "r", this defaults to FORMAT_AUTO. Otherwise, the |
| 64 | default is FORMAT_XZ. |
| 65 | |
| 66 | check specifies the integrity check to use. This argument can |
| 67 | only be used when opening a file for writing. For FORMAT_XZ, |
| 68 | the default is CHECK_CRC64. FORMAT_ALONE and FORMAT_RAW do not |
| 69 | support integrity checks - for these formats, check must be |
| 70 | omitted, or be CHECK_NONE. |
| 71 | |
| 72 | When opening a file for reading, the *preset* argument is not |
| 73 | meaningful, and should be omitted. The *filters* argument should |
| 74 | also be omitted, except when format is FORMAT_RAW (in which case |
| 75 | it is required). |
| 76 | |
| 77 | When opening a file for writing, the settings used by the |
| 78 | compressor can be specified either as a preset compression |
| 79 | level (with the *preset* argument), or in detail as a custom |
| 80 | filter chain (with the *filters* argument). For FORMAT_XZ and |
| 81 | FORMAT_ALONE, the default is to use the PRESET_DEFAULT preset |
| 82 | level. For FORMAT_RAW, the caller must always specify a filter |
| 83 | chain; the raw compressor does not support preset compression |
| 84 | levels. |
| 85 | |
| 86 | preset (if provided) should be an integer in the range 0-9, |
| 87 | optionally OR-ed with the constant PRESET_EXTREME. |
| 88 | |
| 89 | filters (if provided) should be a sequence of dicts. Each dict |
| 90 | should have an entry for "id" indicating ID of the filter, plus |
| 91 | additional entries for options to the filter. |
| 92 | """ |
| 93 | self._fp = None |
| 94 | self._closefp = False |
| 95 | self._mode = None |
no outgoing calls
searching dependent graphs…