.NET Compatible gzuncompress #54754
-
I am working with a legacy app that has compressed files using PHP's From a bit of disecting, it looks like Is there a way to read/write these values in .NET? Does anyone have any ideas? I would be fine creating a synthetic header/footer for each record and wrapping the value from PHP inside those bytes but I'm not familiar enough with the GZip format to know what to synthesize. Any help? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I believe you can use E.g. consider this PHP code: print(base64_encode(gzcompress("some test data"))); That code prints var inputStream = new MemoryStream(Convert.FromBase64String("eJwrzs9NVShJLS5RSEksSQQAKGMFTw=="));
using var zlibStream = new ZLibStream(inputStream, CompressionMode.Decompress);
using var streamReader = new StreamReader(zlibStream);
string output = streamReader.ReadToEnd(); (Your real code probably won't use base64, this was just an easy way for me to test this out.) |
Beta Was this translation helpful? Give feedback.
-
Are you sure that GZipStream is the right format and not DeflateStream? My understanding was that ZLib, which the php gzcompress documentation calls out uses the deflate algorithm. I had to deal with something similar recently, decoding open street map pbf data, which is a protocol buffer format that uses zlib to compress blobs internally. I finally got the DeflateStream to decompress the data, but the caveat was that DeflateStream expects the stream to not contain a zlib header. The zlib header adds a two byte header to the start and a 4 byte checksum to the end of the data. By trimming these off ( |
Beta Was this translation helpful? Give feedback.
I believe you can use
ZLibStream
for this, which is a new type in .Net 6.E.g. consider this PHP code:
That code prints
eJwrzs9NVShJLS5RSEksSQQAKGMFTw==
. You can then read it in .Net 6 preview like this:(Your real code probably won't use base64, this was just an easy way for me to test this out.)