I am trying to decompress a compressed base64 encoded string but have no idea how to do so. It is not a gzip and I am trying to decompress it without having to write to a file.
Asked
Active
Viewed 643 times
-1
-
related: http://stackoverflow.com/questions/17212964/net-zlib-inflate-with-net-4-5 – Jf Beaulac Jun 29 '16 at 04:02
-
1Step 1: understand how the data was compressed – David Heffernan Jun 29 '16 at 04:22
-
Please provide the base64 encoding of the data here, or at least the first hundred characters. – Mark Adler Jun 29 '16 at 04:36
-
Possible duplicate of [Unzip a memorystream (Contains the zip file) and get the files](http://stackoverflow.com/questions/12715945/unzip-a-memorystream-contains-the-zip-file-and-get-the-files) – Jun 29 '16 at 04:39
1 Answers
0
Tried suggestions from Unzip a memorystream (Contains the zip file) and get the files and finally found one that works with some changes made to use it as a method.
public static string DecompressData(string val)
{
byte[] bytes = Convert.FromBase64String(val).ToArray();
Stream data = new MemoryStream(bytes);
Stream unzippedEntryStream;
MemoryStream ms = new MemoryStream();
ZipArchive archive = new ZipArchive(data);
foreach (ZipArchiveEntry entry in archive.Entries)
{
unzippedEntryStream = entry.Open();
unzippedEntryStream.CopyTo(ms);
}
string result = Encoding.UTF8.GetString(ms.ToArray());
return result;
}