C#通过7Z解压和压缩文件

前言

在网络情况不够良好或者网速受限情况下,传输文件时,一般考虑使用压缩算法对文件进行压缩。7z压缩是一个压缩率比较高的软件,我们可以通过他来处理我们的文件。主要有两种方式进行压缩:方式1,直接通过调用库方式,可以在网上找到他的库算法;方式2,通过CMD命令行模式调用。

1、直接调用库

直接调用库,有一个好处是后期可控制性比较好,它还提供了一个处理回调函数。可以查看处理情况。但传递参数较多,需要好好研究研究。

        //文件压缩处理
        private void ProcessFileEncode(string inputName, string outputName)
        {
            Stream inStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);

            FileStream outStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);

            FileStream trainStream = null;
            Int32 dictionary = 1 << 23;

            Int32 posStateBits = 2;
            Int32 litContextBits = 3;
            Int32 litPosBits = 0;
            Int32 algorithm = 2;
            Int32 numFastBytes = 128;

            bool eos = true;

            CoderPropID[] propIDs =
            {
                    CoderPropID.DictionarySize,
                    CoderPropID.PosStateBits,
                    CoderPropID.LitContextBits,
                    CoderPropID.LitPosBits,
                    CoderPropID.Algorithm,
                    CoderPropID.NumFastBytes,
                    CoderPropID.MatchFinder,
                    CoderPropID.EndMarker
                };
            object[] properties =
            {
                    dictionary,
                    posStateBits,
                    litContextBits,
                    litPosBits,
                    algorithm,
                    numFastBytes,
                    "bt4",
                    eos
                };

            Encoder 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值