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

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

Related

Append to Azure blob zip file

I've found tons of information about how to create and upload a zip file to Azure storage, but I'm trying to see if there's a good way to add content to an existing zip file in blob storage that doesn't involve downloading the whole blob, rebuilding in memory, then uploading again.
My use case involves zipping several hundred, up to several million, items into an archive to be stored in Azure blob storage for later download. I have code that will handle splitting so I don't wind up with a single several-GB size file, but I still run into memory management issues when dealing with large quantities of files. I'm trying to address this by creating the zip file in blob storage, and adding subsequent files to it one by one. I recognize this will incur cost for the additional writes, and that's fine.
I know how to use Append Blobs and Block Blobs, and I have working code to create the zip file and upload, but I can't seem to find out if there's a way to do this. Anyone managed to accomplish this, or able to confirm that this is not possible?
Since you're dealing with zip files, only way to add new files to an existing zip file is to download the blob, add new file to that zip file and then reupload that blob.

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?

how can I download Image array as zip file in asp.net

There is a Image array which name is "images" and there are 50 pictures in that array. How can I download that array as .zip file in asp.net?
Use the Image.Save method to save your image to a memory stream
Use the ZipFile Class or the Ionic.Zip library to create a Zip with these image streams.
Make a controller action, and return that zip file as a FileResult. You can use the Controller.File method to help you out.

C# Get specific file Zip azure File Storage

I was wondering if it is possible to get a specific file in a ZIP from Azure File Storage without downloading and unzipping the whole ZIP.
The problem is that the zip file can be large (>1 gb), while the file in the zip which I need is just a few MB tops.
If it is possible, could you provide an example or link(s)?
Thank you
I was wondering if it is possible to get a specific file in a ZIP from
Azure File Storage without downloading and unzipping the whole ZIP.
No. You would need to download the entire file from storage, unzip the file and then extract the desired file. It is possible to keep the entire downloaded file in memory (in form of stream) and have a zipping library work on that stream instead of saving the entire file on the disk. But you have to read the entire file.

How to decompress bytes from a zip file in 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.

Categories