I think the main problem may be C # uses UTF-16 encoded strings. This can lead to a problem similar to yours. Like any other encoding problem, we may need a little luck, but I think you can solve this by doing:
decompressed_data = gz.read().decode('utf-16')
There, decpressed_data should be Unicode , and you can consider it as such for further work.
UPDATE: This worked for me:
C sharp
static void Main(string[] args) { FileStream f = new FileStream("test", FileMode.CreateNew); using (StreamWriter w = new StreamWriter(f)) { w.Write(Compress("hello")); } } public static string Compress(string s) { var bytes = Encoding.Unicode.GetBytes(s); using (var msi = new MemoryStream(bytes)) using (var mso = new MemoryStream()) { using (var gs = new GZipStream(mso, CompressionMode.Compress)) { msi.CopyTo(gs); } return Convert.ToBase64String(mso.ToArray()); } }
Python
import base64 import cStringIO import gzip f = open('test','rb') s = base64.standard_b64decode(f.read()) buff = cStringIO.StringIO(s) with gzip.GzipFile(fileobj=buff) as gz: decompressed_data = gz.read() print decompressed_data.decode('utf-16')
Without decode('utf-16) it prints to the console:
>>>hello
everything turned out with him:
>>>hello
Good luck, hope this helps!
source share