0

Does anyone know how I can get the compressed contents of a GzipStream?

I just want to read all bytes without decompressing so I can get the length and forward onto a web request with the content-length. The source of the file is from RavenFS which is compressed as it is sent and the length is unknown.

Any help would be appreciated.

Lenny D
  • 1,734
  • 4
  • 22
  • 43
  • Use `new FileStream(...)` instead of `new GZipStream(...)` and read raw bytes. – Alexander Petrov May 23 '17 at 12:37
  • I'm not using GZipStream. The response from my resource is a GzipStream so it's not my choice. I want to get the raw bytes from a GZipStream – Lenny D May 23 '17 at 12:44
  • So you have no choice. – Alexander Petrov May 23 '17 at 12:46
  • Maybe the question should be this, "How can I get the length of a GzipStream without decompressing it?" – Lenny D May 23 '17 at 12:49
  • You can't. [GZipStream.CanSeek](https://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.canseek(v=vs.110).aspx) return `false` in all cases. – Alexander Petrov May 23 '17 at 12:53
  • `GZipStream` is not seekable therefore it cannot return `Length`, `Position` and so on. – Alexander Petrov May 23 '17 at 12:57
  • I know , hence my original question. "How can I get the compressed contents of a gzipstream" It seems crazy to me that I can't read the whole contents of a GzipStream to say a MemoryStream (Compressed bytes) and get the length? I seem to be missing something here. I just want to send gzipped contents to a browser with "Content-Encoding : gzip" with the length set. I'm sure this has been done many times?? – Lenny D May 23 '17 at 12:58
  • Maybe `BaseStream` property helps you? – Alexander Petrov May 23 '17 at 13:02
  • Thanks. That also seems to un-compress the data. Not sure how though ? anyway - taking a different approach. Seems I can set the Transfer-Encoding as chunked and not set a length property – Lenny D May 23 '17 at 14:24

0 Answers0