Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I agree with Cheeso's answer however if the Input file size is greater than 2GB then byte[] buffer = File.ReadAllBytes(pathname); will throw an IO exception. So i modified Cheeso code and it works like a charm for all the files.</p> <h2>.</h2> <pre><code> long maxDataToBuffer = 104857600;//100MB using (var outStream = new FileStream("Out3.zip", FileMode.Create)) { using (var zipStream = new ZipOutputStream(outStream)) { Crc32 crc = new Crc32(); foreach (string pathname in pathnames) { tempBuffLength = maxDataToBuffer; FileStream fs = System.IO.File.OpenRead(pathname); ZipEntry entry = new ZipEntry(Path.GetFileName(pathname)); entry.DateTime = now; entry.Size = buffer.Length; crc.Reset(); long totalBuffLength = 0; if (fs.Length &lt;= tempBuffLength) tempBuffLength = fs.Length; byte[] buffer = null; while (totalBuffLength &lt; fs.Length) { if ((fs.Length - totalBuffLength) &lt;= tempBuffLength) tempBuffLength = (fs.Length - totalBuffLength); totalBuffLength += tempBuffLength; buffer = new byte[tempBuffLength]; fs.Read(buffer, 0, buffer.Length); crc.Update(buffer, 0, buffer.Length); buffer = null; } entry.Crc = crc.Value; zipStream.PutNextEntry(entry); tempBuffLength = maxDataToBuffer; fs = System.IO.File.OpenRead(pathname); totalBuffLength = 0; if (fs.Length &lt;= tempBuffLength) tempBuffLength = fs.Length; buffer = null; while (totalBuffLength &lt; fs.Length) { if ((fs.Length - totalBuffLength) &lt;= tempBuffLength) tempBuffLength = (fs.Length - totalBuffLength); totalBuffLength += tempBuffLength; buffer = new byte[tempBuffLength]; fs.Read(buffer, 0, buffer.Length); zipStream.Write(buffer, 0, buffer.Length); buffer = null; } fs.Close(); } zipStream.Finish(); // I dont think this is required at all zipStream.Flush(); zipStream.Close(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload