本文整理匯總了Python中brotli.Decompressor方法的典型用法代碼示例。如果您正苦於以下問題:Python brotli.Decompressor方法的具體用法?Python brotli.Decompressor怎麽用?Python brotli.Decompressor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類brotli
的用法示例。
在下文中一共展示了brotli.Decompressor方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def __init__(self, out: StreamReader, encoding: Optional[str]) -> None:
self.out = out
self.size = 0
self.encoding = encoding
self._started_decoding = False
if encoding == 'br':
if not HAS_BROTLI: # pragma: no cover
raise ContentEncodingError(
'Can not decode content-encoding: brotli (br). '
'Please install `brotlipy`')
self.decompressor = brotli.Decompressor()
else:
zlib_mode = (16 + zlib.MAX_WBITS
if encoding == 'gzip' else -zlib.MAX_WBITS)
self.decompressor = zlib.decompressobj(wbits=zlib_mode)
示例2: test_drip_feed
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def test_drip_feed(simple_compressed_file):
"""
Sending in the data one byte at a time still works.
"""
with open(simple_compressed_file[0], 'rb') as f:
uncompressed_data = f.read()
with open(simple_compressed_file[1], 'rb') as f:
compressed_data = f.read()
outdata = []
o = brotli.Decompressor()
for i in range(0, len(compressed_data)):
outdata.append(o.decompress(compressed_data[i:i+1]))
outdata.append(o.flush())
outdata.append(o.finish())
assert b''.join(outdata) == uncompressed_data
示例3: __init__
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def __init__(self):
self._obj = brotli.Decompressor()
示例4: gzip_decompressor
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def gzip_decompressor():
"""
Decompressor which can handle decompress gzip stream
"""
return zlib.decompressobj(16 + zlib.MAX_WBITS)
示例5: try_brotli_init
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def try_brotli_init():
try:
import brotli
def brotli_decompressor():
decomp = brotli.Decompressor()
decomp.unused_data = None
return decomp
BufferedReader.DECOMPRESSORS['br'] = brotli_decompressor
except ImportError: #pragma: no cover
pass
#=================================================================
示例6: test_decompressobj
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def test_decompressobj(simple_compressed_file):
with open(simple_compressed_file[0], 'rb') as f:
uncompressed_data = f.read()
with open(simple_compressed_file[1], 'rb') as f:
compressed_data = f.read()
o = brotli.Decompressor()
data = o.decompress(compressed_data)
data += o.flush()
data += o.finish()
assert data == uncompressed_data
示例7: test_streaming_decompression_fails_properly_on_garbage
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def test_streaming_decompression_fails_properly_on_garbage(exception_cls):
"""
Garbage data properly fails decompression.
"""
o = brotli.Decompressor()
with pytest.raises(exception_cls):
o.decompress(b'some random garbage')
示例8: test_compressed_data_with_dictionaries
# 需要導入模塊: import brotli [as 別名]
# 或者: from brotli import Decompressor [as 別名]
def test_compressed_data_with_dictionaries(s, dictionary):
d = brotli.Decompressor(dictionary)
compressed = brotli.compress(s, dictionary=dictionary)
uncompressed = d.decompress(compressed)
assert uncompressed == s