A file object providing transparent bzip2 (de)compression.
A BZ2File can act as a wrapper for an existing file object, or refer
directly to a named file on disk.
Note that BZ2File provides a *binary* file interface - data read is
returned as bytes, and data to be written should be given as bytes.
3.3: Support was added for filename being a file object instead of an actual filename. The 'a' (append) mode was added, along with support for reading multi-stream files.
3.4: The 'x' (exclusive creation) mode was added.
3.5: The read() method now accepts an argument of None.
3.6: Accepts a path-like object.
3.9: The buffering parameter has been removed. It was ignored and deprecated since Python 3.0. Pass an open file object to control how the file is opened. The compresslevel parameter became keyword-only.
3.10: This class is thread unsafe in the face of multiple simultaneous readers or writers, just like its equivalent classes in gzip and lzma have always been.