簡體   English   中英

使用C#DotNetZip提取字節數組變量

[英]Extract a bytearray variable using C# DotNetZip

我有一個C#函數,它接收壓縮的ByteArray作為參數。 我需要提取此byteArray並將生成的未壓縮byteArray發送給另一個函數。 我需要幫助提取zipBytesunzippedBytes請參考下面的偽代碼:

使用Zlib.net的解決方案!

byte[] receiveZipByte (byte[] zipBytes)

{

    MemoryStream oInStream = new MemoryStream(pZFileData);
    ZInputStream oZInstream = new ZInputStream(oInStream);
    MemoryStream oOutStream = new MemoryStream();

    byte[] buffer = new byte[2000];
    int len;
    while ((len = oZInstream.read(buffer, 0, 2000)) > 0)
    {
        oOutStream.Write(buffer, 0, len);
    }

    byte[] pFileData = oOutStream.ToArray();
    oZInstream.Close();
    oOutStream.Close();
   return unzippedBytes;
}

如果您要嘗試解壓縮使用zlib壓縮的數據,我建議使用ZLib.NET庫: http : //www.componentace.com/zlib_.NET.htm

這將取決於您要如何處理數據。 但是,這是將流與DotNetZip一起使用的示例:

 using (var input = new ZipInputStream(new MemoryStream(zipBytes))) { ZipEntry e; while ((e = input.GetNextEntry()) != null) { if (e.IsDirectory) continue; using (var output = File.Open(e.FileName, FileMode.Create, FileAccess.ReadWrite)) { while ((n = input.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, n); } } } } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM