c# - Decompressing a Zip file from a string -


i'm fetching object couchbase 1 of fields has file. file zipped , encoded in base64.

how able take string , decompress original file?

then, if i'm using asp.mvc 4 - how send browser downloadable file?

the original file being created on linux system , decoded on windows system (c#).

you should use convert.frombase64string bytes, decompress, , use controller.file have client download file. decompress, need open zip file using sort of zip library. .net 4.5's built-in ziparchive class should work. or use library, both sharpziplib , dotnetzip support reading streams.

public actionresult myaction() {     string base64string = // linux system     byte[] zipbytes = convert.frombase64string(base64string);     using (var zipstream = new memorystream(zipbytes))     using (var ziparchive = new ziparchive(zipstream))     {         var entry = ziparchive.entries.single();         string mimetype = mimemapping.getmimemapping(entry.name);         using (var decompressedstream = entry.open())             return file(decompressedstream, mimetype);     } } 

you'll need mime type of file, can use mimemapping.getmimemapping common types.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -