当前位置: 首页>>代码示例>>Python>>正文


Python snappy.decompress方法代码示例

本文整理汇总了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) 
开发者ID:ciena,项目名称:afkak,代码行数:27,代码来源:codec.py

示例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 
开发者ID:aff4,项目名称:pyaff4,代码行数:33,代码来源:aff4_image.py

示例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)) 
开发者ID:standy66,项目名称:purerpc,代码行数:12,代码来源:buffers.py

示例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 
开发者ID:standy66,项目名称:purerpc,代码行数:28,代码来源:buffers.py

示例5: decompress

# 需要导入模块: import snappy [as 别名]
# 或者: from snappy import decompress [as 别名]
def decompress(self, data):
        return data 
开发者ID:intake,项目名称:intake,代码行数:4,代码来源:serializer.py

示例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) 
开发者ID:intake,项目名称:intake,代码行数:5,代码来源:serializer.py

示例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) 
开发者ID:pluralsight,项目名称:spavro,代码行数:31,代码来源:datafile.py

示例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
    # 
开发者ID:ethereum,项目名称:lahja,代码行数:13,代码来源:base.py

示例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) 
开发者ID:ethereum,项目名称:trinity,代码行数:7,代码来源:gossiper.py

示例10: decompress

# 需要导入模块: import snappy [as 别名]
# 或者: from snappy import decompress [as 别名]
def decompress(self, data: bytes) -> bytes:
        return snappy.decompress(data) 
开发者ID:ethereum,项目名称:trinity,代码行数:4,代码来源:commands.py

示例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) 
开发者ID:ethereum,项目名称:trinity,代码行数:16,代码来源:commands.py


注:本文中的snappy.decompress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。