本文整理匯總了Python中snappy.decompress方法的典型用法代碼示例。如果您正苦於以下問題:Python snappy.decompress方法的具體用法?Python snappy.decompress怎麽用?Python snappy.decompress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類snappy
的用法示例。
在下文中一共展示了snappy.decompress方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: snappy_decode
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def snappy_decode(payload):
if not has_snappy():
raise NotImplementedError("Snappy codec is not available")
if payload.startswith(_XERIAL_HEADER):
# TODO ? Should become a fileobj ?
view = memoryview(payload)
out = []
length = len(payload)
cursor = 16
while cursor < length:
block_size = struct.unpack_from('!i', view, cursor)[0]
# Skip the block size
cursor += 4
end = cursor + block_size
# XXX snappy requires a bytes-like object but doesn't accept
# a memoryview, so we must copy.
out.append(snappy.decompress(view[cursor:end].tobytes()))
cursor = end
# See https://atleastfornow.net/blog/not-all-bytes/
return b''.join(out)
else:
return snappy.decompress(payload)
示例2: doDecompress
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def doDecompress(self, cbuffer, chunk_id):
if self.compression == lexicon.AFF4_IMAGE_COMPRESSION_ZLIB :
if len(cbuffer) == self.chunk_size:
return cbuffer
return zlib.decompress(cbuffer)
elif self.compression == lexicon.AFF4_IMAGE_COMPRESSION_SNAPPY_SCUDETTE:
# Backwards compatibility with Scudette's AFF4 implementation.
# Chunks are always compressed.
return snappy.decompress(cbuffer)
elif self.compression == lexicon.AFF4_IMAGE_COMPRESSION_SNAPPY:
if len(cbuffer) == self.chunk_size:
# Buffer is not compressed.
return cbuffer
try:
return snappy.decompress(cbuffer)
except Exception as e:
raise e
elif self.compression == lexicon.AFF4_IMAGE_COMPRESSION_STORED:
return cbuffer
else:
raise RuntimeError(
"Unable to process compression %s" % self.compression)
# This class implements Evimetry's AFF4 pre standardisation effort
示例3: decompress
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def decompress(self, data):
if self._message_encoding == "gzip" or self._message_encoding == "deflate":
import zlib
return zlib.decompress(data)
elif self._message_encoding == "snappy":
import snappy
return snappy.decompress(data)
else:
raise UnsupportedMessageEncodingError(
"Unsupported compression: {}".format(self._message_encoding))
示例4: _parse_one_message
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def _parse_one_message(self):
# either compressed_flag = message_length = flow_controlled_length = None and
# compressed_flag, message_length are the next elements in self._buffer, or they are all
# not None, and the next element in self._buffer is data
if self._message_length is None:
if len(self._buffer) < 5:
return None, 0
message_header, self._flow_controlled_length = self._buffer.popleft_flowcontrol(5)
self._compressed_flag, self._message_length = struct.unpack('>?I', message_header)
if self._message_length > self._max_message_length:
# Even after the error is raised, the state is not corrupted, and parsing
# can be safely resumed
raise MessageTooLargeError(
"Received message larger than max: {message_length} > {max_message_length}".format(
message_length=self._message_length,
max_message_length=self._max_message_length,
)
)
if len(self._buffer) < self._message_length:
return None, 0
data, flow_controlled_length = self._buffer.popleft_flowcontrol(self._message_length)
flow_controlled_length += self._flow_controlled_length
if self._compressed_flag:
data = self.decompress(data)
self._compressed_flag = self._message_length = self._flow_controlled_length = None
return data, flow_controlled_length
示例5: decompress
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def decompress(self, data):
return data
示例6: decode
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def decode(self, bytestr, container):
return self._format_encoder.decode(
self._compressor.decompress(bytestr), container)
示例7: _read_block_header
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def _read_block_header(self):
self.block_count = self.raw_decoder.read_long()
if self.codec == "null":
# Skip a long; we don't need to use the length.
self.raw_decoder.skip_long()
self._datum_decoder = self._raw_decoder
elif self.codec == 'deflate':
# Compressed data is stored as (length, data), which
# corresponds to how the "bytes" type is encoded.
data = self.raw_decoder.read_bytes()
# -15 is the log of the window size; negative indicates
# "raw" (no zlib headers) decompression. See zlib.h.
uncompressed = zlib.decompress(data, -15)
self._datum_decoder = io.BinaryDecoder(StringIO(uncompressed))
elif self.codec == 'snappy':
# Compressed data includes a 4-byte CRC32 checksum
length = self.raw_decoder.read_long()
data = self.raw_decoder.read(length - 4)
uncompressed = snappy.decompress(data)
self._datum_decoder = io.BinaryDecoder(StringIO(uncompressed))
self.raw_decoder.check_crc32(uncompressed);
elif self.codec == 'xz':
# Compressed data is stored as (length, data), which
# corresponds to how the "bytes" type is encoded.
data = self.raw_decoder.read_bytes()
uncompressed = lzma.decompress(data)
self._datum_decoder = io.BinaryDecoder(StringIO(uncompressed))
else:
raise DataFileException("Unknown codec: %r" % self.codec)
示例8: _decompress_event
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def _decompress_event(self, data: Union[BaseEvent, bytes]) -> BaseEvent:
if isinstance(data, BaseEvent):
return data
else:
import snappy
return cast(BaseEvent, pickle.loads(snappy.decompress(data)))
#
# Remote Endpoint Management
#
示例9: _deserialize_gossip
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def _deserialize_gossip(
compressed_data: bytes, sedes: ssz.BaseSedes
) -> ssz.Serializable:
data = snappy.decompress(compressed_data)
return ssz.decode(data, sedes)
示例10: decompress
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def decompress(self, data: bytes) -> bytes:
return snappy.decompress(data)
示例11: decode
# 需要導入模塊: import snappy [as 別名]
# 或者: from snappy import decompress [as 別名]
def decode(cls: Type[TCommand], message: MessageAPI, snappy_support: bool) -> TCommand:
if snappy_support:
payload_data = cls.compression_codec.decompress(message.encoded_payload)
else:
payload_data = message.encoded_payload
try:
payload = cls.serialization_codec.decode(payload_data)
except rlp.exceptions.DeserializationError as err:
raise rlp.exceptions.DeserializationError(
f"DeserializationError for {cls}",
err.serial,
) from err
return cls(payload)