簡體   English   中英

解壓縮和回壓縮不會返回相同的內容

[英]Decompress and Compress back does not return the same content

在使用DeflateStream解壓縮並壓縮回字節數組后,為什么不能得到相同的內容?

編碼:

byte[] originalcontent = Same Byte Array Content
byte[] decompressedBytes;
byte[] compressedBackBytes;

// Decompress the original byte-array
using (Stream contentStream = new MemoryStream(originalcontent, false))
using (var zipStream = new DeflateStream(contentStream, CompressionMode.Decompress))
using (var decStream = new MemoryStream())
{
    zipStream.CopyTo(decStream);
    decompressedBytes = decStream.ToArray();
}

// Compress the byte-array back
using (var input = new MemoryStream(decompressedBytes, true))
using (var compressStream = new MemoryStream())
using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
{
    input.CopyTo(compressor);
    compressedBackBytes = compressStream.ToArray();
}

為什么originalcontent!= compressionBackBytes?

看起來您已正確完成了所有操作,直到獲取原始輸入流並改寫了包含解壓縮字節的壓縮器為止。 您需要將壓縮器字節放入CompressedBackBytes中。

您的輸入(從解壓縮開始)似乎將已解壓縮的字節復制到其中; 然后將其復制到壓縮器中,該壓縮器將覆蓋剛剛解壓縮的內容。

也許你的意思是

compressedBackBytes = compressor.ToArray();

暫無
暫無

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

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