Will not decompress data. When reading from GzipStream, the number of bytes read = 0. Version .NET 3.5, what could be wrong?

zipStream = new GzipStream(memoryStream, CompressionMode.Decompress); memoryStream.Write(data, 0, data.Length); int count = zipStream.Read(buffer, 0, buffer.Length); 
  • You need to translate the memorial at the beginning: memoryStream.Position = 0 - Alexander Petrov
  • I did move the position after writing to the stream, did not help, step by step debugging also shows 0 read bytes. - Egor Ohotin
  • Uh-uh ... Looked at the code more closely. You need to write in zipStream , but not in memoryStream . - Alexander Petrov
  • Initially this was the case, but the stream is closed for recording, recording is done in the case of compression, and data is being taken from the memorial stream. And here InvalidOperationException throws if you try to write, and the stream is open only for reading during decompression - Egor Okhotin

1 answer 1

It turned out to read

 memoryStream.Write(data, 0, data.Length); memoryStream.Position = 0; var b = zipStream.ReadByte(); int count = zipStream.Read(buffer, 0, buffer.Length);