• 大小: 18KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: 其他
  • 标签: 7z  api  sdk  demo  最简单  

资源简介

最简单的7Z SDK用法 DEMO API: Zip(Stream inStream, Stream outStream) Unzip(Stream inStream, Stream outStream) 包括全部源代码, visual studio 2010, 打开就可以用!100% 这是我测试的结果: Input length 100000 Output length 268 Ziped rate 0.268% Input length 268 Output length 100000 UnZiped rate 37313.4328358209%

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SevenZip;

namespace Demo7zApi
{
    class Program
    {
        public static void Zip(Stream inStream Stream outStream)
        {
            bool dictionaryIsDefined = false;
            Int32 dictionary = 1 << 21;

            if (!dictionaryIsDefined)
                dictionary = 1 << 23;

            Int32 posStateBits = 2;
            Int32 litContextBits = 3; // for normal files
            // UInt32 litContextBits = 0; // for 32-bit data
            Int32 litPosBits = 0;
            // UInt32 litPosBits = 2; // for 32-bit data
            Int32 algorithm = 2;
            Int32 numFastBytes = 128;
            string mf = “bt4“;
            bool eos = false;

            CoderPropID[] propIDs = 
{
CoderPropID.DictionarySize
CoderPropID.PosStateBits
CoderPropID.LitContextBits
CoderPropID.LitPosBits
CoderPropID.Algorithm
CoderPropID.NumFastBytes
CoderPropID.MatchFinder
CoderPropID.EndMarker
};
            object[] properties = 
{
(Int32)(dictionary)
(Int32)(posStateBits)
(Int32)(litContextBits)
(Int32)(litPosBits)
(Int32)(algorithm)
(Int32)(numFastBytes)
mf
eos
};

            SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();
            encoder.SetCoderProperties(propIDs properties);
            encoder.WriteCoderProperties(outStream);
            Int64 fileSize;

            fileSize = inStream.Length;
            for (int i = 0; i < 8; i++)
                outStream.WriteByte((Byte)(fileSize >> (8 * i)));

            encoder.Code(inStream outStream -1 -1 null);
        }


        public static void Unzip(Stream inStream Stream outStream)
        {
            byte[] properties = new byte[5];
            if (inStream.Read(properties 0 5) != 5)
                throw (new Exception(“input .lzma is too short“));
            SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
            decoder.SetDecoderProperties(properties);

            long outSize = 0;
            for (int i = 0; i < 8; i++)
            {
                int v = inStream.ReadByte();
                if (v < 0)
                    throw (new Exception(“Can‘t Read 1“));
                outSize |= ((long)(byte)v) << (8 * i);
            }
            long compressedSize = inStream.Length - inStream.Position;
            decoder.Code(inStream outStream compressedSize outSize null);
        }

        static int Main(string[] args)
        {
            try
            {
                byte[] bytes = new byte[100000];
                for (byte i = 0; i < 100; i++)
                {
                    for (int j = 0; j < 1000; j++)
                    {
                        bytes[i *

评论

共有 条评论