本文整理匯總了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