當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。