ICSharpCode.SharpZipLib 使用演示

using System;
using System.Data;
using System.IO;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;

namespace Test.CUI
{
  class Zip
  {
    static void CompressFile()
    {
      FileStream ins = File.OpenRead("1.jpg");
      FileStream outs = File.Create("test.zip");
      
      ZipOutputStream s = new ZipOutputStream(outs);
      s.SetLevel(5);
      s.Password = "123456";

      ZipEntry entry = new ZipEntry("1.jpg");
      s.PutNextEntry(entry);

      byte[] buffer = new byte[ins.Length];
      ins.Read(buffer, 0, buffer.Length);
      s.Write(buffer, 0, buffer.Length);

      s.Finish();
      s.Close();
    }

    static MemoryStream UnCompressToMemory()
    {
      ZipInputStream s = new ZipInputStream(File.OpenRead("test.zip"));
      s.Password = "123456";
      
      ZipEntry theEntry = s.GetNextEntry();
      Console.WriteLine(theEntry.Name);

      MemoryStream ms = new MemoryStream((int)theEntry.Size);
      byte[] data = new byte[1024 * 100];
 
      while (true)
      {
        int size = s.Read(data, 0, data.Length);

        if (size > 0)
        {
          ms.Write(data, 0, size);
        }
        else
        {
          break;
        }
      }

      Console.WriteLine(ms.Length);
      s.Close();

      return ms;
    }

    static void UpCompressToFile()
    {
      
    }
  }
}
阅读更多
文章标签: buffer byte system class
想对作者说点什么? 我来说一句

<em>ICSharpCode.SharpZipLib</em>.dll

2018年05月07日 0B 下载

<em>SharpZipLib</em>_0860_Bin.zip

2018年05月09日 0B 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭