I'm trying zip 100 000 dynamic files, and on console app i can do it without any problem, but on web app it appears that it's at some kind impossible for my current knowledge level. I would like to know is it really impossible ?
So far zip made on webapp that is bigger than 65535 files crashes on opening.
What I have tried:
I made this test apps but I wasn't able to find answer.
console
static void Main(string[] args)
{
using (ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create("Test.zip")))
{
zipOutputStream.SetLevel(0);
for (long i = 1; i < 100000; i++)
{
string txt = "File " + i.ToString();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(txt);
using (MemoryStream ms = new MemoryStream(bytes))
{
ZipEntry entry =
new ZipEntry(ZipEntry.CleanName(i.ToString() + ".txt"))
{
DateTime = DateTime.Now,
CompressionMethod = CompressionMethod.Stored,
Size = bytes.Length
};
zipOutputStream.PutNextEntry(entry);
byte[] buffer = new byte[1024];
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(ms, zipOutputStream, buffer);
Console.WriteLine(i.ToString());
}
}
}
}
web
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ClearHeaders();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + "file.zip");
using (ZipOutputStream zipOutputStream = new ZipOutputStream(Response.OutputStream))
{
zipOutputStream.SetLevel(0);
for (long i = 1; i < 100000; i++)
{
string txt = "File " + i.ToString();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(txt);
using (MemoryStream ms = new MemoryStream(bytes))
{
ZipEntry entry =
new ZipEntry(ZipEntry.CleanName(i.ToString() + ".txt"))
{
DateTime = DateTime.Now,
CompressionMethod = CompressionMethod.Stored,
Size = bytes.Length
};
zipOutputStream.PutNextEntry(entry);
byte[] buffer = new byte[1024];
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(ms, zipOutputStream, buffer);
Response.Flush();
}
}
}
Response.Flush();
Response.End();
}