[
  {
    "Id": "666826",
    "ThreadId": "271286",
    "Html": "\r\n<p>Hello,</p>\r\n<p>I was trying to to create asp.net page that returns&nbsp;a dynamically generated uncompressed zip.</p>\r\n<p>Filesize may vary between 50MB to 2GB.</p>\r\n<p>On my local machine running it in debug mode succeeds about half the time I try calling it (and half the time the save method throws an unhandled execption) and on the server it just hangs. Any sugestions about changes that might affect stability?</p>\r\n<p>Also, as I understand it &nbsp;the zip.Save(System.IO.OutputStream) should work with only the buffersize and continuously send the result to the outpustream.</p>\r\n<p>Am I correct here?</p>\r\n<p>And the actual code (Nothing fancy, basically the usual&nbsp;asp.net example):</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>    <span style=\"color:blue\">private</span> <span style=\"color:blue\">static</span> <span style=\"color:blue\">void</span> SendZipArchive(<span style=\"color:blue\">string</span> fileName, <span style=\"color:blue\">string</span> storagePath)\r\n        {\r\n\r\n            <span style=\"color:green\">//if (!System.IO.Directory.Exists(storagePath))</span>\r\n            <span style=\"color:green\">//{</span>\r\n            <span style=\"color:green\">//    HttpContext.Current.Response.Write(&quot;File not available.&quot;);</span>\r\n            <span style=\"color:green\">//    HttpContext.Current.Response.End();</span>\r\n            <span style=\"color:green\">//}</span>\r\n            <span style=\"color:blue\">string</span>[] fileNames = System.IO.Directory.GetFiles(storagePath);\r\n\r\n            HttpContext.Current.Response.Clear();\r\n            String ReadmeText = <span style=\"color:#a31515\">&quot;This is a zip file dynamically generated at &quot;</span> &#43; System.DateTime.Now.ToString(<span style=\"color:#a31515\">&quot;G&quot;</span>);\r\n            HttpContext.Current.Response.ContentType = <span style=\"color:#a31515\">&quot;application/zip&quot;</span>;\r\n            HttpContext.Current.Response.AddHeader(<span style=\"color:#a31515\">&quot;content-disposition&quot;</span>, <span style=\"color:#a31515\">&quot;attachment; filename=&quot;</span> &#43; fileName);\r\n            <span style=\"color:blue\">using</span> (ZipFile zip = <span style=\"color:blue\">new</span> ZipFile())\r\n            {\r\n                <span style=\"color:green\">//zip.ForceNoCompression = true;</span>\r\n                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.None;\r\n                zip.BufferSize = 65536 * 8;\r\n                <span style=\"color:blue\">foreach</span> (<span style=\"color:blue\">string</span> filePath <span style=\"color:blue\">in</span> fileNames)\r\n                {\r\n                    zip.AddFile(filePath, <span style=\"color:blue\">string</span>.Empty);\r\n\r\n                }\r\n\r\n                zip.Save(HttpContext.Current.Response.OutputStream);\r\n            }\r\n            HttpContext.Current.Response.End();\r\n            <span style=\"color:green\">//throw new NotImplementedException();</span>\r\n        }\r\n</pre>\r\n<pre>Regards Martin</pre>\r\n</div>\r\n",
    "PostedDate": "2011-09-02T06:44:36.413-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "666860",
    "ThreadId": "271286",
    "Html": "<p>Hello Martin,</p>\r\n<p>Your understanding of the ZipFile.Save() method and its use of the specified buffersize is correct.</p>\r\n<p>But, ASPNET by default buffers output written to Response.OutputStream.&nbsp; That means, while DotNetZip will not keep all of the zipped content in memory, ASPNET <strong>will</strong>.&nbsp; To tell ASPNET to NOT buffer the output, you must set Response.BufferOutput to false.&nbsp; This will cause ASPNET to use Chunked Transfer-encoding of the HTTP response - in practice it will transmit the data bytes to the browser/client, as your app writes them into Response.OutputStream.</p>\r\n<p>You can observe this by using an HTTP Debugging proxy like Fiddler.</p>\r\n<p>best</p>\r\n<p>-Dino</p>",
    "PostedDate": "2011-09-02T07:38:07.157-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "667018",
    "ThreadId": "271286",
    "Html": "<p>Hello Dino,</p>\r\n<p>Thanks, I should have thought of that one myself. I'll fire up fiddler,&nbsp;turn of the buffering and continue testing come monday.</p>\r\n<p>My initial idea was actually to manually make a zip header and a zip ending and just stream it with the files in between ( no need for libraries or any processing of files since there is no compression), but I decided to go with the possibility to add compression if we were going to be reusing this for other stuff.</p>\r\n<p>Cheers Martin.</p>",
    "PostedDate": "2011-09-02T14:23:55.233-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]