.NetGZipStreamクラスを使用してファイルを圧縮および解凍しています。解凍を実行すると、データは正常に見えますが、特定の、一見恣意的なポイントの後で、ゼロになります。たとえば、ファイルを解凍した後のサイズは適切な19KBですが、バイト10,588以降はすべてゼロです。
何を間違っているのかわかりません。
これが私が圧縮を行う方法です:
Byte[] bytes = GetFileBytes(file);
using (FileStream fileStream = new FileStream("Zipped.gz", FileMode.Create))
{
using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Compress))
{
zipStream.Write(bytes, 0, bytes.Length);
}
}
そして、これが私が解凍を行う方法です(Bytesは圧縮されたバイトの配列であり、OriginalSizeは圧縮される前のファイルのサイズです):
using (MemoryStream memoryStream = new MemoryStream(Bytes))
{
using (GZipStream zipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
{
// Note: Since the compressed version can be larger, I use the larger of the original and the compressed size for the decompressed array's size.
Byte[] decompressedBytes = new Byte[OriginalSize > Bytes.Length ? OriginalSize : Bytes.Length];
Int32 numRead = zipStream.Read(decompressedBytes, 0, Bytes.Length);
using (FileStream fileStream = new FileStream("Decompressed.txt", Name), FileMode.Create))
{
fileStream.Write(decompressedBytes, 0, Convert.ToInt32(OriginalSize));
}
}
}