uses zlibex
procedure varianttostream(const v: olevariant; stream: tstream);
varp : pointer;
begin
stream.position := 0;
stream.size := vararrayhighbound (v, 1) - vararraylowbound (v, 1) + 1;
p := vararraylock (v);
stream.write (p^, stream.size);
vararrayunlock (v);
stream.position := 0;
end;
procedure streamtovariant(stream: tstream; var v: olevariant);
varp : pointer;
begin
v := vararraycreate ([0, stream.size - 1], varbyte);
p := vararraylock (v);
stream.position := 0;
stream.read (p^, stream.size);
vararrayunlock (v);
end;
function compressdata(v: olevariant): olevariant;
varm, m0: tmemorystream;
begin
m := tmemorystream.create;
m0 := tmemorystream.create;
tryif v = null then exit;
varianttostream(v,m); //轉換到流
m.position := 0;
zcompressstream(m, m0); //壓縮流
streamtovariant(m0, v); //轉換到變體返回值
finally
m.free;
m0.free
end;
result := v;
end;
function decompressdata(v: olevariant): olevariant;
varm, m0: tmemorystream;
begin
m := tmemorystream.create;
m0 := tmemorystream.create;
tryif v = null then exit;
varianttostream(v,m); //轉換到流
m.position := 0;
zdecompressstream(m, m0); //壓縮流
streamtovariant(m0, v); //轉換到變體返回值
finally
m.free;
m0.free
end;
result := v;
end;
關於壓縮和解壓縮
從http www.icsharpcode.net 首先需要在專案裡引用sharpziplib.dll。然後修改其中的關於壓縮和解壓縮的類。實現原始碼如下 壓縮檔案 using system using system.io using icsharpcode.sharpziplib.checksum...
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...