How to use C # compressed files and attention!

xiaoxiao2021-03-06  105

Preferred, first find an open source C # compression component. Such as: ICSHARPCODE.SHARPZIPLIB Download Ues: http://www.icsharpcode.net/opensource/sharpziplib/default.aspx can do what you need according to its own. I am using this component, I have encountered a problem. There is no error when compressed small files. Once the source file reaches 150m, it will let your machine collapsed. (At least my machine), why, because if the source file is 150M, you will need to apply for a 150M size byte array in memory. A better machine is still no problem, and the general machine can be miserable. If the file is in a big, the good machine can't stand it. In order to solve the problem of large file compression, the method of segmentation compression can be used.

private string CreateZIPFile (string path, int M) {try {Crc32 crc = new Crc32 (); ICSharpCode.SharpZipLib.Zip.ZipOutputStream zipout = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream (System.IO.File.Create (path ". ZIP ")); system.io.filestream fs = system.io.file.openread (path); long pai = 1024 * 1024 * m; // Write a long forint = fs.length / pai 1 per m toint; byte [] buffer = null; ZipEntry entry = new ZipEntry (System.IO.Path.GetFileName (path)); entry.Size = fs.Length; entry.DateTime = DateTime.Now; zipout.PutNextEntry (entry); for ( Long i = 1; i <= forint; i ) {IF (PAI * i

转载请注明原文地址:https://www.9cbs.com/read-103845.html

New Post(0)