关闭

ICSharpCode.SharpZipLib 使用演示

标签: bufferbytesystemclass
771人阅读 评论(0) 收藏 举报
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()
    {
      
    }
  }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20610次
    • 积分:305
    • 等级:
    • 排名:千里之外
    • 原创:9篇
    • 转载:6篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论
    Well link