Search code examples
.netdotnetzip

DotNetZip Get uncompressed stream without uncompressing the whole stream


I have a ZipEntry record and I need to read a couple of bytes of it (the whole size is several hundred megabytes). There is ZipEntry.Extract method but as I understand it extracts the whole record. Is there any way to get some stream which would uncompress only data I need.


Solution

  • You can't do that. The compression scheme doesn't allow you to only read a certain part of the data contained in an entry. You can only read it by starting from the beginning and working right the way through.

    Edit: If you just want to read a segment from the beginning of a file, you can use ZipEntry.OpenReader() to get a stream, but it's likely non-seekable so you can't read data from the middle. (or if you can, there will be a performance penalty as it decompresses)