91网首页-91网页版-91网在线观看-91网站免费观看-91网站永久视频-91网站在线播放

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

推薦一個C#開發(fā)的、跨平臺的解壓縮的開源項,值得收藏

admin
2023年8月16日 9:34 本文熱度 1306
解壓縮對于我們?nèi)粘9ぷ魈?jīng)常用到了,畢竟它有諸多好處,比如節(jié)省空間、方便管理傳輸、保密作用等等。
而對于我們開發(fā)人員來說,項目開發(fā)也是經(jīng)常需要用到,今天就給大家推薦用一個可以用于壓縮、解壓、解密,并支持多種壓縮類型和格式的開源項目。

項目簡介

這是一個純C#壓縮庫,用于.NET Standard 2.0、2.1、.NET Core 3.1和.NET 5.0,支持格式有zip/tar/bzip2/gzip/lzip,功能實現(xiàn)有解壓縮rar, 解壓縮7zip, 解壓縮zip, 解壓縮tar解壓縮bzip2, 解壓縮gzip, 解壓縮lzip。

項目結(jié)構(gòu)

使用方法

壓縮核心代碼

protected void Write(CompressionType compressionType, string archive, string archiveToVerifyAgainst, Encoding encoding = null)

{

using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive)))

   {

      WriterOptions writerOptions = new WriterOptions(compressionType)

      {

         LeaveStreamOpen = true,

      };

 

      writerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;

 

using (var writer = WriterFactory.Open(stream, type, writerOptions))

      {

         writer.WriteAll(ORIGINAL_FILES_PATH, "*", SearchOption.AllDirectories);

      }

   }

   CompareArchivesByPath(Path.Combine(SCRATCH2_FILES_PATH, archive),

      Path.Combine(TEST_ARCHIVES_PATH, archiveToVerifyAgainst));

 

using (Stream stream = File.OpenRead(Path.Combine(SCRATCH2_FILES_PATH, archive)))

   {

      ReaderOptions readerOptions = new ReaderOptions();

 

      readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;

 

using (var reader = ReaderFactory.Open(NonDisposingStream.create(stream), readerOptions))

      {

         reader.WriteAllToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions()

         {

            ExtractFullPath = true

         });

      }

   }

   VerifyFiles();

}

解壓核心代碼

public abstract class ReaderTests : TestBase

{

         protected void Read(string testArchive, CompressionType expectedCompression, ReaderOptions options = null)

         {

                   testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);

 

                   options = options ?? new ReaderOptions();

 

                   options.LeaveStreamOpen = true;

                   ReadImpl(testArchive, expectedCompression, options);

 

                   options.LeaveStreamOpen = false;

                   ReadImpl(testArchive, expectedCompression, options);

                   VerifyFiles();

         }

 

         private void ReadImpl(string testArchive, CompressionType expectedCompression, ReaderOptions options)

         {

         using (var file = File.OpenRead(testArchive))

                   {

         using (var protectedStream = NonDisposingStream.create(new ForwardOnlyStream(file), throwOnDispose: true))

                            {

         using (var testStream = new TestStream(protectedStream))

                                     {

         using (var reader = ReaderFactory.Open(testStream, options))

                                               {

                                                        UseReader(reader, expectedCompression);

                                                        protectedStream.ThrowOnDispose = false;

                                                        Assert.False(testStream.IsDisposed, "{nameof(testStream)} prematurely closed");

                                               }

 

         // Boolean XOR -- If the stream should be left open (true), then the stream should not be diposed (false)

         // and if the stream should be closed (false), then the stream should be disposed (true)

         var message = $"{nameof(options.LeaveStreamOpen)} is set to '{options.LeaveStreamOpen}', so {nameof(testStream.IsDisposed)} should be set to '{!testStream.IsDisposed}', but is set to {testStream.IsDisposed}";

                                               Assert.True(options.LeaveStreamOpen != testStream.IsDisposed, message);

                                     }

                            }

                   }

         }

 

         public void UseReader(IReader reader, CompressionType expectedCompression)

         {

         while (reader.MoveToNextEntry())

                   {

         if (!reader.Entry.IsDirectory)

                            {

                                     Assert.Equal(expectedCompression, reader.Entry.CompressionType);

                                     reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions()

                                     {

                                               ExtractFullPath = true,

                                               Overwrite = true

                                     });

                            }

                   }

         }

}

zip壓縮用法

Write(CompressionType.None, "Zip.none.noEmptyDirs.zip", "Zip.none.noEmptyDirs.zip", Encoding.UTF8);

zip解壓用法

Read("Zip.zipx", CompressionType.LZMA);

項目還未支持
  • RAR 5 解密

  • 7Zip 寫入

  • Zip64  解壓縮

  • 多卷Zip支持


項目地址:https://github.com/adamhathcock/sharpcompress

- End -

該文章在 2023/8/16 9:39:40 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产黄大片在线视频 | 黑人免费 | 区芒果视频 | 精品乱伦中文国产 | 成人h网站| 中文字幕第二页 | 国产激情a∨ | 91电影院 | 国产放荡对白视 | 日本专区在线观看 | 成人看片黄a在线 | 国产精品欧美专区 | 漂亮的保姆6| 欧美日韩国产字幕 | 日本电影精品久 | 午夜福利手机看片 | 欧美亚洲综合色 | 制服丝袜第一页在线 | 日本高清一 | 国产性爱 | 国产高清在线精品 | 午夜福利区| 青青青欧美视频在线 | 日本精品人 | 91天堂国产网站 | 伦理电影一区二区 | 伦理片免费观在线看 | 区一区二不卡 | 乱伦亚洲影视三级 | 国产精品欧美电影 | 国产馆精品丝 | 欧美性爱二区 | 日韩伦理影 | 成人午夜福利A视频 | 91视频91视频 | 精品国产呦| 国产精品码一区 | 日本三级乱伦国产 | 国产高清不卡一区 | 人在线播放 | 国产一区二区免费 |