Thursday 15 August 2013

c# - Creating a ZIP Archive in Memory Using System.IO.Compression -


I try to create a zip archive with a simple demo text file as a MemoryStream I am doing the following types:

  (var memoryStream = new MemoryStream ()) (var archive = new ziparchive (memorystream, zipArchiveMode.Create)) {var demoFile = archive.CreateEntry ( "Foo.txt"); (Var entryStream = demoFile.Open ()) (var streamWriter = new streamer (entry stream)) {streamWriter.Write ("bar!"); } (Var filestream = New Flamestream (@ "C: \ Test Test.zip", Flamemade. Creat)) {using stream.CopyTo (fileStream); }}   

If I run this code, the archive file is created automatically but foo.txt is not.

However, if I change the MemoryStream with the file stream directly, the archive is created correctly:

 using  ( Var fileStream = new FileStream (@ "C: \ Temp \ test Zip", FileMode.Create)) {var archive = new ziparchive (filestream, filemode.create)) {// ...}   

Is this a memorystream to FileStream ?

To create a zip archive <(Var archive = new ziparchive (memorystream, zipArchiveMode.Create, true ) By using {var demoFile = archive.CreateEntry

  (var memoryStream = new MemoryStream ()) ("foo.txt"); (Var entryStream = demoFile.Open ()) (var streamWriter = new streamer (entry stream)) {streamWriter.Write ("bar!"); }}   

Before we can use it (var filestream = new filestream (@ "C: \ test test". MemoryStream.CopyTo (FileStream);}} , We need to deal with the zipper curve, which means that 'true' is to be given as zirperchmic in the third parameter so that we can reach the stream even after it is settled. < / Html>

No comments:

Post a Comment