0

i want use GZip compression algorithme in PHP & C#.

Code in C#

byte[] bs1 = File.ReadAllBytes(inName);
memoryStream1 = new MemoryStream();
gZipStream = new GZipStream(memoryStream1, CompressionMode.Compress);
gZipStream.Write(bs1, 0, (int)bs1.Length);
gZipStream.Close();

Code in PHP

$data = file_get_contents(inName);
$gzip = gzencode($data);

I have try all gzip php functions and all compression level. I dont have the same result, same result is needed for crc check. Thanks for your help.

Source string              : This is a test !
gzencode + base64 inphp    : H4sIAAAAAAAACwvJyCxWAKJEhZLU4hIFRQDdPPQVEAAAAA==
gZipStream  + base64 in C# : H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/It7Miyal/2Vpmzdt+rv+P9089BUQAAAA
EPIC FAIL
  • 1
  • 1
  • 3
  • Welcome on Stackoverflow. Maybe you can show us the CRC method as well. Perhaps the problem is there. – Thomas Weller Dec 28 '14 at 21:18
  • Did you try it with a short input string and have compared the byte array results? – Jan Köhler Dec 28 '14 at 21:18
  • I have post the string – EPIC FAIL Dec 28 '14 at 21:28
  • Try this c code? http://www.cprogramdevelop.com/2093066/ – Pieter De Clercq Dec 28 '14 at 21:31
  • I use gzdecode for décompression and work perfectly, have only the problem with gzencode on php. – EPIC FAIL Dec 28 '14 at 21:33
  • Are you complaining not that result in PHP or C# is incorrect, but that PHP and C# gave you correct but different results, are not you? – user4003407 Dec 29 '14 at 00:21
  • Can you decompress the PHP-compressed data using C# code, and/or vice a versa? Gzip has multiple options, and .NET doesn't offer precise control over all of them (and maybe PHP doesn't either, but I don't know anything about that). As long as both output valid gzip data (i.e. can be decompressed by a correct gzip implementation), I don't see that there's actually anything wrong here. – Peter Duniho Dec 29 '14 at 08:03

0 Answers0