I have a bunch of data in a byte[]
, I compress it using a GZipStream
like this.
byte[] input = ...;
var zipped = new MemoryStream();
using (var zipper = new GZipStream(zipped, CompressionMode.Compress, true)) {
zipper.Write(input, 0, input.Length);
}
Due to my technical requirements I need to split the result into - let's say - 50k
chunks, so that each chunk can be decompressed and restores a corresponding chunk of the original data.
If I just split the result byte[]
, the chunks won't form a valid GZip archive any more so that's not a good way.
I neither can use some kind of loop to stop zipping at a chunk size because GZipStream
cannot report the current length of the zipped data unfortunately. I only get the Length
when I close the zipping stream, but then I already have a valid archive so I cannot just continue from there.
How could I do this while keeping each chunk as a valid GZip archive?