0

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.

SiberianGuy
  • 24,674
  • 56
  • 152
  • 266

1 Answers1

1

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)

PhonicUK
  • 13,486
  • 4
  • 43
  • 62
  • The zip format, but the same applies to pretty much any compression scheme. You may find that you can get a read-forward-only stream, but that'd only be useful if you just wanted to read some bytes from the beginning of the file. – PhonicUK Sep 10 '12 at 14:59
  • So even if I need to get two first bytes I have to extract the whole zip file entry? – SiberianGuy Sep 10 '12 at 15:00
  • You can use ZipEntry.OpenReader() which will give you a readable stream if you just want stuff from the beginning of the file. See my updated answer. – PhonicUK Sep 10 '12 at 15:02