Python snappy.StreamCompressor() Examples

The following are 5 code examples of snappy.StreamCompressor(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module snappy , or try the search function .
Example #1
Source File: compression.py    From filesystem_spec with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, infile, mode, **kwargs):
        import snappy

        self.details = {"size": 999999999}  # not true, but OK if we don't seek
        super().__init__(fs=None, path="snappy", mode=mode.strip("b") + "b", **kwargs)
        self.infile = infile
        if "r" in mode:
            self.codec = snappy.StreamDecompressor()
        else:
            self.codec = snappy.StreamCompressor() 
Example #2
Source File: snappy.py    From gnsq with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, socket):
        self._decompressor = snappy.StreamDecompressor()
        self._compressor = snappy.StreamCompressor()
        super(SnappySocket, self).__init__(socket) 
Example #3
Source File: request_responder.py    From trinity with MIT License 5 votes vote down vote up
def _write_with_snappy(data: bytes, stream: INetStream) -> None:
    compressor = StreamCompressor()
    data_reader = io.BytesIO(data)
    chunk = data_reader.read(MAX_CHUNK_SIZE)
    while chunk:
        chunk = compressor.add_chunk(chunk)
        await stream.write(chunk)
        chunk = data_reader.read(MAX_CHUNK_SIZE) 
Example #4
Source File: compressor.py    From pghoard with Apache License 2.0 5 votes vote down vote up
def __init__(self, src_fp, algorithm, level=0):
        super().__init__(src_fp, minimum_read_size=32 * 1024)
        if algorithm == "lzma":
            self._compressor = lzma.LZMACompressor(lzma.FORMAT_XZ, -1, level, None)
        elif algorithm == "snappy":
            self._compressor = snappy.StreamCompressor()
        elif algorithm == "zstd":
            self._compressor = zstd.ZstdCompressor(level=level).compressobj()
        else:
            InvalidConfigurationError("invalid compression algorithm: {!r}".format(algorithm)) 
Example #5
Source File: snappyfile.py    From pghoard with Apache License 2.0 5 votes vote down vote up
def __init__(self, next_fp, mode):
        if snappy is None:
            raise io.UnsupportedOperation("Snappy is not available")

        if mode == "rb":
            self.decr = snappy.StreamDecompressor()
            self.encr = None
        elif mode == "wb":
            self.decr = None
            self.encr = snappy.StreamCompressor()
        else:
            raise io.UnsupportedOperation("unsupported mode for SnappyFile")

        super().__init__(next_fp)
        self.decr_done = False