[
  {
    "Id": "1303940",
    "ThreadId": "567227",
    "Html": "I am using DotNetZip library and I want to do the following steps:\r<br />\n<br />\n1 Add same files into ZipFile object\r<br />\n<br />\n2 Save the archive into MemoryMappedViewStream stream\r<br />\n<br />\n3 Read archive parts from stream and save them (individually) on the HDD\r<br />\n<br />\nThe following code add files in archive and save archive on MemoryMappedViewStream object\r<br />\n<br />\nvar zip = new ZipFile();<br />\n<pre><code>    int SegmentsCreated = 0;\n    var archieveVolumSize = 600 * 1024; // 600k segments\n    zip.MaxOutputSegmentSize = archieveVolumSize;\n    long maximumSize = 0;\n    foreach (var file in df.GetFiles().Take(5))\n    {\n        zip.AddFile(file.Name);\n    }\n    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;\n    MemoryStream ms = new MemoryStream();\n    zip.Save(ms);\n    ms.Seek(0, SeekOrigin.Begin);\n    ms.Flush();\n    SegmentsCreated = zip.NumberOfSegmentsForMostRecentSave;\n    zip.Dispose();\n    var achieveLength = ms.Length;\n    MemoryMappedFile mmf = MemoryMappedFile.CreateNew(&quot;ArhiveZip&quot;, ms.Length);\n    MemoryMappedViewStream stream = mmf.CreateViewStream();\n    stream.Write(ms.GetBuffer(), 0, (int)ms.Length);\n    stream.Flush();\n    stream.Close();\n    stream.Dispose();\n    ms.Close();\n    ms.Dispose();</code></pre>\n\nBefore to save the archive in a Stream object I saved it on HDD and I could extract files from it.\r<br />\n<br />\nWith the following code I tried to save individually volume archive on HDD\r<br />\n<br />\nstream = mmf.CreateViewStream();<br />\n<pre><code>    var iterations = Math.Ceiling(achieveLength * 1.0 / archieveVolumSize);\n    long positionStart = 0;\n    for (int i = 1; i &lt; iterations; i++)\n    {\n        byte[] bytes = new byte[archieveVolumSize];\n        stream.Read(bytes, 0, archieveVolumSize);\n        File.WriteAllBytes(&quot;ZipArhive.z0&quot; + (i), bytes);\n        positionStart += archieveVolumSize;\n    }\n\n    var archiveBytes = new byte[achieveLength - positionStart];\n    stream.Read(archiveBytes, 0, archiveBytes.Length);\n    File.WriteAllBytes(&quot;ZipArhive.zip&quot;, archiveBytes);\n    stream.Dispose();\n    mmf.Dispose();</code></pre>\n\nThe problem is that after I saved individually volume I cannot extract files from the resulted archive.\r<br />\n<br />\nI had no exception on runtime but if I click Extract here (using WinRar program) it doesn't do anything.\r<br />\n<br />\nYou can find this question on stackoverflow at <a href=\"http://stackoverflow.com/questions/25802069/dotnetzip-read-archive-from-stream\" rel=\"nofollow\">this</a> link\r<br />\nThank you in advance<br />\n",
    "PostedDate": "2014-09-12T00:54:51.533-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]