bz2
— 支持
bzip2
压缩
¶
源代码: Lib/bz2.py
This module provides a comprehensive interface for compressing and decompressing data using the bzip2 compression algorithm.
The
bz2
module contains:
-
The
open()函数和BZ2Fileclass for reading and writing compressed files. -
The
BZ2CompressorandBZ2Decompressorclasses for incremental (de)compression. -
The
compress()anddecompress()functions for one-shot (de)compression.
文件的 (解) 压缩 ¶
- bz2. open ( filename , mode = 'rb' , compresslevel = 9 , encoding = None , errors = None , newline = None ) ¶
-
Open a bzip2-compressed file in binary or text mode, returning a 文件对象 .
As with the constructor for
BZ2File, filename argument can be an actual filename (astrorbytesobject), or an existing file object to read from or write to.The mode argument can be any of
'r','rb','w','wb','x','xb','a'or'ab'对于二进制模式,或'rt','wt','xt',或'at'for text mode. The default is'rb'.The compresslevel argument is an integer from 1 to 9, as for the
BZ2File构造函数。For binary mode, this function is equivalent to the
BZ2File构造函数:BZ2File(filename, mode, compresslevel=compresslevel)。在此情况下, encoding , errors and newline arguments must not be provided.对于文本模式,
BZ2Fileobject is created, and wrapped in anio.TextIOWrapperinstance with the specified encoding, error handling behavior, and line ending(s).Added in version 3.3.
3.4 版改变: The
'x'(exclusive creation) mode was added.3.6 版改变: 接受 像路径对象 .