How to decompress bytes from a zip file in C# - c#

My program handles zip files with encrypted headers, it decrypts the headers and shows the info. Now I want to view the pictures within the zip file in a picturebox so I have to decompress the files into a memorystream.
I have all the bytes of the compressed files. Wich means: header, compressed data, extra length.
How can I decompress these bytes so I can view the file?

You should use the ZipArchive class to read the compressed data, since it appears you're reading valid zip files.
If you're using .NET 4 or older, you'll have to use a third-party library, like DotNetZip and its ZipInputStream class.

Related

Difference between downloading into a file Or stream for ZipArchive extraction

I want to download a big file (2,5 GB) with .Net WebClient.
Step 1
Now I can download the zip file:
Persist it as local file with webclient.DownloadFile method
OR
Persist into a stream with webclient.OpenRead method
Step 2
.Net ZipArchive does accept a stream or a local file path.
I want to extract the .zip file and read the folders/files extracted.
What is the better approach local file/stream concerning Step 2?

Unpacking tar/BZ2 files using C#

I have a tar.bz2 file and I want to extract it to a directory. In the examples I only see option of compress or decompress however I want actually to extract or unpack.
Also tried ICSharpCode.SharpZipLib.BZip2 but I didn't find an option to unpack.
While you use a ZipInputStream for .zip files, you should use a BZip2InputStream for .bz2 files (and GZipInputStream for .gz files etc.).
Taken from:
How to decompress .bz2 file in C#?
Decompressing and unpacking are two different operations. A foo.tar.bz2 file is actually a foo.tar file which was then compressed using bz2.
So to get single files you have to do this in the opposite direction. I.e. first decompress it (which you managed to do with sharpziplib). The result of this decompression has then to be untared (which can also be done with sharpziplib) see the docs for details.

Huffman algorithm for decompress an already compressed bytes

I have a byte array in the database which has been compressed using the Huffman algorithm in Delphi. Now I need to decompress it in SSIS (SQL Server Integration Services).
I need some C#/.NET code, or a tool to decrypt the bytes into a file, based on the Huffman algorithm. There are a few tools in the market that unpack a compressed file, but I don't have the file with full header for LHA compression. I need a way to somehow convert a series of bytes to a decompressed file, and then save it to a file.
With Huffman compression, each character in your input file will map to a sequence of bits. If you have access to the Delphi source code, you can try to figure out how the frequency and character mapping information was done. Is the mapping included in the compressed file? You will need that mapping in order to write the code to decompress the file.

How do I extract a ZIP file on the fly with DotNetZip?

In my Windows Azure code I want to download a ZIP file from Blob Storage and unzip it on the fly and store the unzipped contents to the disk. This way I save on first writing the file to the disk and then reading it when doing the extraction.
I'm trying to use DotNetZip for that.
The ZIP file is originally very big, so it is cut into pieces (not multipart archive, but a plain ZIP archive, just cut into smaller files) and each piece is uploaded into Blob Storage. I know how to iterate through all the parts and open each blob when neededn
Azure SDK has CloudBlob.OpenRead() that returns a Stream descendant.
DotNetZip has ZipInputStream class that has a constructor accepting a Stream.
How do I connect these pieces together so that I can download the ZIP file pieces one by one and get them extracted on the fly?
Create your own stream class that will return data from the corresponding CloudBlob according to its position.
Then use this class a input stream for your ZipInputStream.
public sealed class ZipBlobStream : Stream
{
...
http://msdn.microsoft.com/library/system.io.stream.aspx

How with sharpziplib get a zip file in memorystream or byte array format and unpack it

I have an app that downloads from ftp and gets the format in memorystream or byte array-it gets the zip file ALREADY ZIPPED ,how can i use sharpziplib with this input to unpack that content to a specific place on my harddrive
Wrap the raw data in a MemoryStream and then pass this to the zip library instead of a FileStream.

Categories