本文整理汇总了Python中bz2.BZ2Decompressor方法的典型用法代码示例。如果您正苦于以下问题:Python bz2.BZ2Decompressor方法的具体用法?Python bz2.BZ2Decompressor怎么用?Python bz2.BZ2Decompressor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bz2
的用法示例。
在下文中一共展示了bz2.BZ2Decompressor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stream_padding
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def test_stream_padding(self):
# Test for bug #1543303.
tar = tarfile.open(tmpname, self.mode)
tar.close()
if self.mode.endswith("gz"):
with gzip.GzipFile(tmpname) as fobj:
data = fobj.read()
elif self.mode.endswith("bz2"):
dec = bz2.BZ2Decompressor()
with open(tmpname, "rb") as fobj:
data = fobj.read()
data = dec.decompress(data)
self.assertTrue(len(dec.unused_data) == 0,
"found trailing data")
else:
with open(tmpname, "rb") as fobj:
data = fobj.read()
self.assertTrue(data.count("\0") == tarfile.RECORDSIZE,
"incorrect zero padding")
示例2: test_stream_padding
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def test_stream_padding(self):
# Test for bug #1543303.
tar = tarfile.open(tmpname, self.mode)
tar.close()
if self.mode.endswith("gz"):
fobj = gzip.GzipFile(tmpname)
data = fobj.read()
fobj.close()
elif self.mode.endswith("bz2"):
dec = bz2.BZ2Decompressor()
data = open(tmpname, "rb").read()
data = dec.decompress(data)
self.assertTrue(len(dec.unused_data) == 0,
"found trailing data")
else:
fobj = open(tmpname, "rb")
data = fobj.read()
fobj.close()
self.assertTrue(data.count("\0") == tarfile.RECORDSIZE,
"incorrect zero padding")
示例3: init
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def init(self):
import bz2
self.pos = 0
if self.mode == "r":
self.bz2obj = bz2.BZ2Decompressor()
self.fileobj.seek(0)
self.buf = b""
else:
self.bz2obj = bz2.BZ2Compressor()
示例4: init
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def init(self):
import bz2
self.pos = 0
if self.mode == "r":
self.bz2obj = bz2.BZ2Decompressor()
self.fileobj.seek(0)
self.buf = ""
else:
self.bz2obj = bz2.BZ2Compressor()
示例5: _read_bzip
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def _read_bzip(self, coder, input):
dec = bz2.BZ2Decompressor()
return self._read_from_decompressor(coder, dec, input)
示例6: _read_bzip
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def _read_bzip(self, coder, input):
dec = bz2.BZ2Decompressor()
return self._read_from_decompressor(coder, dec)
示例7: __init__
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def __init__(self, stream):
self.bzip2 = BZ2Decompressor()
示例8: __init__
# 需要导入模块: import bz2 [as 别名]
# 或者: from bz2 import BZ2Decompressor [as 别名]
def __init__(self, fileobj):
self._fileobj = fileobj
self._bz2 = bz2.BZ2Decompressor()
self._line_buffer = collections.deque([""])
self._current_line = ""
self._current_offset = 0