C#中用SharpZipLib生成gzip/解压文件

Code tells all:

成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的龙湾网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

using System;
using System.IO;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Core;

namespace CNKIDataExport
{
    class Program
    {
        public static void gZipFile(string filePath, string zipFilePath)
        {
            Stream s = new GZipOutputStream(File.Create(zipFilePath));
            FileStream fs = File.OpenRead(filePath);
            int size;
            byte[] buf = new byte[4096];
            do
            {
                size = fs.Read(buf, 0, buf.Length);
                s.Write(buf, 0, size);
            } while (size > 0);
            s.Close();
            fs.Close();
        }

        public static void gunZipFile(string zipFilePath, string filePath)
        {
            using (Stream inStream = new GZipInputStream(File.OpenRead(zipFilePath)))
            using (FileStream outStream = File.Create(filePath))
            {
                byte[] buf = new byte[4096];
                StreamUtils.Copy(inStream, outStream, buf);
            }
        }

        static void Main(string[] args)
        {
            string src = @"D:\test\in.txt"
            string dest = @"D:\test\out.gz"
            string ori = @"D:\test\ori.txt"

            gZipFile(src, dest);
            Console.WriteLine("gzip over!");
            gunZipFile(dest, ori);
            Console.WriteLine("gunzip over!");
            Console.ReadKey();
        }
    }
}

相关链接:

1、SharpZipLib下载

2、Using SharpZipLib to gzip a file

3、ICSharpCode.SharpZipLib.GZip.GZipInputStream Class Reference

4、C#利用SharpZipLib解压或压缩文件夹实例操作(ZIP格式)

*** walker ***


网页名称:C#中用SharpZipLib生成gzip/解压文件
文章起源:http://bzwzjz.com/article/popjhg.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站设计制作报价 成都网站建设推广 成都网站建设 自适应网站建设 成都网站制作 梓潼网站设计 成都网站建设公司 成都响应式网站建设 高端网站建设 阿坝网站设计 成都网站设计 成都网站建设公司 网站制作 营销型网站建设 企业网站建设 H5网站制作 成都企业网站设计 成都网站建设 专业网站建设 手机网站建设 成都定制网站建设 网站制作