本文整理汇总了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