溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

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

發(fā)布時(shí)間:2020-06-23 21:56:16 來(lái)源:網(wǎng)絡(luò) 閱讀:3926 作者:RQSLT 欄目:編程語(yǔ)言

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();
        }
    }
}


相關(guān)鏈接:

1、SharpZipLib下載

2、Using SharpZipLib to gzip a file

3、ICSharpCode.SharpZipLib.GZip.GZipInputStream Class Reference

4、C#利用SharpZipLib解壓或壓縮文件夾實(shí)例操作(ZIP格式)


*** walker ***


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI