MCPcopy Index your code
hub / github.com/python/cpython / LZMAFile

Class LZMAFile

Lib/lzma.py:38–276  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

36
37
38class 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

Callers 15

xzopenMethod · 0.90
test_initMethod · 0.90
test_init_modeMethod · 0.90
test_init_with_x_modeMethod · 0.90
test_init_bad_modeMethod · 0.90
test_init_bad_checkMethod · 0.90
test_init_bad_presetMethod · 0.90
test_closeMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_initMethod · 0.72
test_init_modeMethod · 0.72
test_init_with_x_modeMethod · 0.72
test_init_bad_modeMethod · 0.72
test_init_bad_checkMethod · 0.72
test_init_bad_presetMethod · 0.72
test_closeMethod · 0.72
test_closedMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…