Skip to content

.NET Compatible gzuncompress #54754

Answered by svick
TonyValenti asked this question in Q&A
Jun 25, 2021 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

I believe you can use ZLibStream for this, which is a new type in .Net 6.

E.g. consider this PHP code:

print(base64_encode(gzcompress("some test data")));

That code prints eJwrzs9NVShJLS5RSEksSQQAKGMFTw==. You can then read it in .Net 6 preview like this:

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.)

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by TonyValenti
Comment options

You must be logged in to vote
1 reply
@svick
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants