Decompress zip file directly from remote source

1k views Asked by At

I want to store some data in zip format on Azure FileStorage.

Can SevenZipSharp (especially the SevenZipExtractor class) work with URLs like https://myaccount.file.core.windows.net/shared1/folder1/data00054.zip instead of local file?

I want to retrieve the file from a remote location, unzip in memory, process the data, and then clean memory.

1

There are 1 answers

1
nvoigt On

It seems you can do that even without any third party library like 7zip:

WebClient OpenRead will get you a stream from your URI and ZipArchive constructor from stream will get you a ZipArchive from it:

var uri = @"https://myaccount.file.core.windows.net/shared1/folder1/data00054.zip";
var wc = new WebClient();

var stream = wc.OpenRead(uri);
var zip = new ZipArchive(stream);

Apply using-blocks as appropriate.

If you really really want to use the third party library, you can find the documentation (in this case, the source) here. As you can see, it can work with arbitrary streams as well:

var uri = @"https://myaccount.file.core.windows.net/shared1/folder1/data00054.zip";
var wc = new WebClient();

var stream = wc.OpenRead(uri);
var extractor = new SevenZipExtractor(stream);