| | 38 | |
|---|
| | 39 | try: |
|---|
| | 40 | import zlib |
|---|
| | 41 | def decompress(data): |
|---|
| | 42 | return zlib.decompress(data) |
|---|
| | 43 | def compress(data): |
|---|
| | 44 | return zlib.compress(data) |
|---|
| | 45 | except ImportError: |
|---|
| | 46 | # Unable to import zlib. If running in IronPython, try using |
|---|
| | 47 | # System.IO.Compression instead. |
|---|
| | 48 | from System import IO, Text |
|---|
| | 49 | _encoding = Text.ASCIIEncoding() |
|---|
| | 50 | def _string_to_bytearr(string): |
|---|
| | 51 | return _encoding.GetBytes(string) |
|---|
| | 52 | def _bytearr_to_string(bytes): |
|---|
| | 53 | return _encoding.GetString(bytes) |
|---|
| | 54 | def _read_bytes(gz, byteArray): |
|---|
| | 55 | pass |
|---|
| | 56 | def decompress(data): |
|---|
| | 57 | bytes = _string_to_bytearr(data) |
|---|
| | 58 | ms = IO.MemoryStream() |
|---|
| | 59 | ms.Write(bytes, 0, bytes.Length) |
|---|
| | 60 | ms.Position = 0 # fseek 0 |
|---|
| | 61 | gz = IO.Compression.GZipStream(ms, IO.Compression.CompressionMode.Decompress) |
|---|
| | 62 | bytes = _read_bytes(gz) |
|---|
| | 63 | retval = _bytearr_to_string(bytes) |
|---|
| | 64 | gz.Close() |
|---|
| | 65 | return retval |
|---|
| | 66 | # implementation not complete or tested, but checked in just for fun. |
|---|
| | 67 | |
|---|
| | 68 | |
|---|