c# - Create zip in .net Core from URLS without downloading on server -


i have list of internet urls trying create zip using memorystream. files on s3 bucket s3 sdk doesnt have function download folder zip.

avoiding save on server , delete those. project running on ubuntu. have tried getting response follows,

var httpclient = new httpclient(); httpclient.defaultrequestheaders.useragent.add(new productinfoheadervalue("myclient", "1.0")); var result = await httpclient.getstreamasync(names[0]); 

however ziparchive class in .net takes local files path , not memorystream

note: cannot use sharpziplib since not supported .net core.

however ziparchive class in .net takes local files path , not memorystream

this untrue, ziparchive class has overloads accept stream instances:

https://msdn.microsoft.com/en-us/library/hh158268(v=vs.110).aspx

initializes new instance of ziparchive class specified stream.

public ziparchive(stream stream) 

(documentation full .net framework, .net core implementation has same interface: https://github.com/dotnet/corefx/blob/master/src/system.io.compression/src/system/io/compression/ziparchive.cs )

like so:

class itemtoadd {     public string name;     public stream content; }  list<itemtoadd> itemstoadd = getitemsfromamazons3();  using( memorystream zipstream = new memorystream() ) {      using( ziparchive zip = new ziparchive( zipstream ) ) {          foreach( itemtoadd item in itemstoadd ) {              ziparchiveentry entry = zip.createentry( item.name );             using( stream entrystream = entry.open() ) {                  item.content.copyto( entrystream );             }         }      }      zipstream.position = 0;      // copy zipstream output, or return directly depending on web framework } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -