def _read_bytes(stream): ms = IO.MemoryStream() buf = Array.CreateInstance(System.Byte, 2048) while True: bytes = stream.Read(buf, 0, buf.Length) if bytes == 0: break else: ms.Write(buf, 0, bytes) retval = ms.ToArray() ms.Close() return retval
def compress(data): bytes = _string_to_bytearr(data) ms = IO.MemoryStream() gz = IO.Compression.DeflateStream( ms, IO.Compression.CompressionMode.Compress, True) gz.Write(bytes, 0, bytes.Length) gz.Close() ms.Position = 0 # fseek 0 bytes = ms.ToArray() retval = _bytearr_to_string(bytes) ms.Close() return retval
def decompress(data): these_bytes = _string_to_bytearr(data) ms = IO.MemoryStream() ms.Write(bytes, 0, these_bytes.Length) ms.Position = 0 # fseek 0 gz = IO.Compression.DeflateStream( ms, IO.Compression.CompressionMode.Decompress) these_bytes = _read_bytes(gz) retval = _bytearr_to_string(these_bytes) gz.Close() return retval
def compress(data): """ data compression """ these_bytes = _string_to_bytearr(data) ms_ = IO.MemoryStream() gz_ = IO.Compression.DeflateStream( ms_, IO.Compression.CompressionMode.Compress, True) gz_.Write(these_bytes, 0, these_bytes.Length) gz_.Close() ms_.Position = 0 # fseek 0 these_bytes = ms_.ToArray() retval = _bytearr_to_string(these_bytes) ms_.Close() return retval