I have a file that could have been created something like this:
stream.Write(headerBytes, 0, headerBytes.Count);
using (var gz = new GZipStream(stream, Compress, leaveOpen: true);
{
gz.Write(otherBytes, 0, otherBytes.Count);
}
stream.Write(moreBytes, 0, moreBytes.Count);
Now when reading the file like
stream.Read(headerBytes, 0, headerBytes.Count);
// in reality I make sure that indeed headerBytes.Count get read,
// something the above line omits
using (var gz = new GZipStream(stream, Decompress, leaveOpen: true)
{
do { /* use buffer... */}
while ((bytesRead = gz.Read(buffer, 0, buffer.Length)) != 0);
}
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
// use buffer...
It turns out that the GZipStream
(same is true for DeflateStream
) reads in 16384 bytes from stream
, instead of the actual 13293 compressed bytes in the case I checked.
Assuming I neither know the size of the compressed part of the file beforehand, nor the number of bytes following the compressed data, is there a way to use GzipStream/DeflateStream
- so it only reads the compressed data from
stream
- or at least figure out what the size of the compressed data part was, so I can
stream.Position -= actuallyRead - compressedSize
manually?