關於壓縮和解壓縮

2021-05-22 18:08:28 字數 2069 閱讀 8626

從http://www.icsharpcode.net

首先需要在專案裡引用sharpziplib.dll。然後修改其中的關於壓縮和解壓縮的類。實現原始碼如下:

///

/// 壓縮檔案

///

using system;

using system.io;

using icsharpcode.sharpziplib.checksums;

using icsharpcode.sharpziplib.zip;

using icsharpcode.sharpziplib.gzip;

namespace compression

system.io.filestream streamtozip = new system.io.filestream(filetozip,system.io.filemode.open , system.io.fileaccess.read);

system.io.filestream zipfile = system.io.file.create(zipedfile);

zipoutputstream zipstream = new zipoutputstream(zipfile);

zipentry zipentry = new zipentry("zippedfile");

zipstream.putnextentry(zipentry);

zipstream.setlevel(compressionlevel);

byte buffer = new byte[blocksize];

system.int32 size =streamtozip.read(buffer,0,buffer.length);

zipstream.write(buffer,0,size);

try

} catch(system.exception ex)

zipstream.finish();

zipstream.close();

streamtozip.close();

}public void zipfilemain(string args)

s.finish();

s.close();}}

}現在再來看看解壓檔案類的原始碼

///

/// 解壓檔案

///

using system;

using system.text;

using system.collections;

using system.io;

using system.diagnostics;

using system.runtime.serialization.formatters.binary;

using system.data;

using icsharpcode.sharpziplib.bzip2;

using icsharpcode.sharpziplib.zip;

using icsharpcode.sharpziplib.zip.compression;

using icsharpcode.sharpziplib.zip.compression.streams;

using icsharpcode.sharpziplib.gzip;

namespace decompression

else

}streamwriter.close();}}

s.close();}}

}有了壓縮和解壓縮的類以後,就要在窗體裡呼叫了。怎麼?是新手,不會呼叫?ok,接著往下看如何在窗體裡呼叫。

首先在窗體裡放置兩個命令按鈕(不要告訴我你不會放啊~),然後編寫以下原始碼

///

/// 呼叫原始碼

///

private void button2_click_1(object sender, system.eventargs e)

private void button2_click(object sender, system.eventargs e)

好了,到此為止,如何壓縮和解壓縮的類都已經完成了,需要的朋友直接拿走調吧。

壓縮和解壓縮OLEVARIANT

uses zlibex procedure varianttostream const v olevariant stream tstream varp pointer begin stream.position 0 stream.size vararrayhighbound v,1 vararra...

C 壓縮和解壓縮

話不多說,直接上 最後有重要說明!哦對了,用的是icsharpcode.sharpziplib.zip 這個東西 壓縮 先宣告個全域性變數吧 附件打包的變數 zipoutputstream zos null 下面就是壓縮的 了 protected void btnfile click object ...

ZipArchive壓縮和解壓縮

利用 cocopods 新增第三方類庫 ziparchive 壓縮 1.根據檔案管理器建立壓縮物件zip nsfilemanager manager nsfilemanager defaultmanager ziparchive zip ziparchive alloc initwithfilema...