博客日历
2025年06月 | ||||||
一 | 二 | 三 | 四 | 五 | 六 | 七 |
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
存档
2025年03月 2024年
03月 04月 05月 2021年
01月 02月 11月 12月 2020年
02月 03月 04月 05月 06月 07月
09月 2018年
09月 2017年
01月 02月 07月 2016年
01月 04月 07月 08月 11月 12月
2015年
01月 02月 03月 05月 09月 10月
11月 2014年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2013年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2012年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2011年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2010年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2009年
03月 04月 05月 06月 07月 08月
09月 10月 11月 12月
在C#中使用lzma SDK压缩与解压缩文件
using System; using System.Collections.Generic; using System.Text; using System.IO; using SevenZip; class Progress : ICodeProgress { public void SetProgress(Int64 inSize, Int64 outSize) { Console.WriteLine("读入{0}KB,处理后大小:{1}字节", inSize/1024, outSize); } } class Program { static void Main(string[] args) { /* 压缩 */ CoderPropID[] propIDs = { CoderPropID.DictionarySize, CoderPropID.PosStateBits, CoderPropID.LitContextBits, CoderPropID.LitPosBits, CoderPropID.Algorithm, CoderPropID.NumFastBytes, CoderPropID.MatchFinder, CoderPropID.EndMarker }; object[] encode_properties = { 1<<23, 2, 3, 0, 2, 128, "bt4", false }; SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder(); encoder.SetCoderProperties(propIDs, encode_properties); FileStream inStream = new FileStream(@"D:\MyDoc\Desktop\test.txt", FileMode.Open, FileAccess.Read); FileStream outStream = new FileStream(@"D:\MyDoc\Desktop\test.txt.7z", FileMode.Create, FileAccess.Write); encoder.WriteCoderProperties(outStream); for (int i = 0; i < 8; i++) { outStream.WriteByte((Byte)(inStream.Length >> (8 * i))); } //压缩进度 //Progress p = new Progress(); encoder.Code(inStream, outStream, -1, -1, /*p*/null); inStream.Close(); outStream.Close(); /* 解压 inStream = new FileStream(@"D:\MyDoc\Desktop\test.txt.7z", FileMode.Open, FileAccess.Read); outStream = new FileStream(@"D:\MyDoc\Desktop\test.decode.txt", FileMode.Create, FileAccess.Write); byte[] decode_properties = new byte[5]; int n = inStream.Read(decode_properties, 0, 5); if (n != 5) { Console.WriteLine("read encode_properties error."); return; } SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder(); decoder.SetDecoderProperties(decode_properties); long outSize = 0; for (int i = 0; i < 8; i++) { int v = inStream.ReadByte(); if (v < 0) { Console.WriteLine("read outSize error."); return; } outSize |= ((long)(byte)v) << (8 * i); } long compressedSize = inStream.Length - inStream.Position; decoder.Code(inStream, outStream, compressedSize, outSize, null); inStream.Close(); outStream.Close(); */ } }
上一篇: 在SQL SERVER2008 R2中创建一个链接到本机的“链接服务器”
下一篇: 自动生成ADO连接字符串的方法
分类:Win32/C++ 查看次数:16819 发布时间:2012/12/4 20:50:57