[
  {
    "Id": "425044",
    "ThreadId": "207681",
    "Html": "<p>I need File.Append sort of functionality inside a Zip files' entry</p>\r\n<p>What i will do is just create a Zip file then for different function I</p>\r\n<p>Have to appned the Text in and entry inside the Zip file.</p>\r\n<p>I doesn't wanted to write all then create the text file and then save the entry in ZipFile.</p>\r\n<p>My File can get from 10KB to 900MB of data.</p>\r\n<p>Please suggest any thing</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>string strZipFileName = @&quot;C:\\test.zip&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strEntryName = strZipFileName + @&quot;\\Test.cpt&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ZipFile zfValid = new ZipFile(@&quot;C:\\test.zip&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] strArr = { &quot;dsf&quot;, &quot;&quot;, &quot;dsfsdf&quot; };<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (StreamWriter sw = File.AppendText(strEntryName))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (String str in strArr)//in actual i will get some info by an ienumerable&lt;string function&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sw.WriteLine(str);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sw.Close();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>",
    "PostedDate": "2010-03-29T11:13:25.807-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "425167",
    "ThreadId": "207681",
    "Html": "<p>I can't think of an easy way to append data to an existing entry in a zip file, without decompressing and re-compressing. Compression is done on the entire file, and so it isn't simple to just &quot;append&quot; additional compressed blocks.&nbsp; You'd need to directly manipulate the DEFLATE format.&nbsp; You are welcome to do that work yourself, but I don't think I want to do it.</p>\r\n<p>The way I would do what you want:&nbsp; in DotNetZip, it is possible to open an entry as a stream - this stream decompresses as you read it (see <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/ea82f312-372e-edad-d374-8db2486e70ba.htm\">ZipEntry.OpenReader</a>).&nbsp; It is also possible&nbsp;to add an entry using a WriteDelegate.&nbsp; DotNetZip calls this delegate upon Save().&nbsp; Putting these things together, your WriteDelegate could call OpenReader, write all the data from the original entry, then append additional data.&nbsp; This would decompress and re-compress of all the original data, but only in memory, without ever writing a temporary file to disk.&nbsp; The code would look like this:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 0.5em 0 0.5em;padding:0.25em .25em 0.25em .25em\">\r\n<pre><span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip1 = ZipFile.Read(zipFile))\r\n{\r\n    <span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n    {\r\n        zip.AddEntry(entryName, (name, stream) =&gt;\r\n            {\r\n                <span style=\"color:Blue\">var</span> src = zip1[name].OpenReader();\r\n                <span style=\"color:Blue\">int</span> n;\r\n                <span style=\"color:Blue\">byte</span>[] b = <span style=\"color:Blue\">new</span> <span style=\"color:Blue\">byte</span>[2048];\r\n                <span style=\"color:Blue\">while</span>((n= src.Read(b,0,b.Length)) &gt; 0)\r\n                    stream.Write(b,0,n);\r\n\r\n                <span style=\"color:Blue\">string</span> update = String.Format(<span style=\"color:#A31515\">&quot;Updating zip file at {0}\\n&quot;</span>, DateTime.Now.ToString(<span style=\"color:#A31515\">&quot;G&quot;</span>));\r\n                <span style=\"color:Blue\">byte</span>[] a = System.Text.Encoding.ASCII.GetBytes(update.ToCharArray());\r\n                stream.Write(a,0,a.Length);\r\n            });\r\n        zip.Save(tempZipFile);\r\n    }\r\n}\r\n\r\nFile.Delete(zipFile);\r\nFile.Move(tempZipFile, zipFile);</pre>\r\n</div>\r\n<p>You would need to save to a separate zip file, because you can't&nbsp;do the decompress/recompress thing I described&nbsp;without using 2 distinct zip files.&nbsp; (or at the very least, 2 distinct zip entries).</p>\r\n<p>If you have a 900mb file and you are doing small updates or small append operations, I would recommend not compressing the file until you are finished appending.</p>\r\n<p>Good luck.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-29T16:43:52.83-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "425248",
    "ThreadId": "207681",
    "Html": "<p>Thnaks cheeso for nicely explaining it.</p>\r\n<p>I will now first create all of my files in a temprorary folder then Add them in a zip file as i think that will be a better option.</p>\r\n<p>Thanks</p>",
    "PostedDate": "2010-03-29T22:51:51.693-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]