On this page
lzma.LZMAFile
Prev: lzma.LZMAError | Up: lzma | Next: lzma.open
Rel: lzma.compress, lzma.decompress, lzma.is_check_supported, lzma.LZMACompressor
Ref: docs.python.org — lzma.LZMAFile
Tags: #public #python3 #stdlib #lzma
Import
import lzma
from lzma import LZMAFile
Signature & Overview
lzma.LZMAFile(filename=None, mode='r', *, format=None, check=-1, preset=None, filters=None)
A file object providing transparent LZMA (de)compression.
Methods & Attributes
LZMAFile.close(self)— Flush and close the file.LZMAFile.closed(...)— True if this file is closed.LZMAFile.detach(self, /)— Disconnect this buffer from its underlying raw stream and return it.LZMAFile.fileno(self)— Return the file descriptor for the underlying file.LZMAFile.flush(self, /)— Flush write buffers, if applicable.LZMAFile.isatty(self, /)— Return whether this is an 'interactive' stream.LZMAFile.mode(...)—LZMAFile.modemethod/property.LZMAFile.name(...)—LZMAFile.namemethod/property.LZMAFile.peek(self, size=-1)— Return buffered data without advancing the file position.LZMAFile.read(self, size=-1)— Read up to size uncompressed bytes from the file.LZMAFile.read1(self, size=-1)— Read up to size uncompressed bytes, while trying to avoid making multiple reads from the underlying stream. Reads up to a buffer's worth of data if size is negative.LZMAFile.readable(self)— Return whether the file was opened for reading.LZMAFile.readinto(self, buffer, /)—LZMAFile.readintomethod/property.LZMAFile.readinto1(self, buffer, /)—LZMAFile.readinto1method/property.LZMAFile.readline(self, size=-1)— Read a line of uncompressed bytes from the file.LZMAFile.readlines(self, hint=-1, /)— Return a list of lines from the stream.LZMAFile.seek(self, offset, whence=0)— Change the file position.LZMAFile.seekable(self)— Return whether the file supports seeking.LZMAFile.tell(self)— Return the current file position.LZMAFile.truncate(self, size=None, /)— Truncate file to size bytes.LZMAFile.writable(self)— Return whether the file was opened for writing.LZMAFile.write(self, data)— Write a bytes object to the file.LZMAFile.writelines(self, lines, /)— Write a list of lines to stream.
Usage
import io
import lzma
buf = io.BytesIO()
with lzma.LZMAFile(buf, "wb") as f:
f.write(b"xz data")
buf.seek(0)
with lzma.LZMAFile(buf, "rb") as f:
assert f.read() == b"xz data"
Gotchas
- Binary mode only: Use
lzma.open(..., "rt", encoding="utf-8")for text.
REPL Inspect
from lzma import LZMAFile
help(LZMAFile)
Linked from
Related notes
- tuts/python3/stdlib_module/lzma/LZMAError Linked here; links to this page; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/open Linked here; links to this page; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/lzma/compress Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/decompress Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/is_check_supported Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/LZMACompressor Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/LZMADecompressor shared tags: #lzma, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib