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:

文件的 (解) 压缩

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 (a str or bytes object), 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.

对于文本模式, BZ2File object is created, and wrapped in an io.TextIOWrapper instance 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 版改变: 接受 像路径对象 .