This project is read-only.

Read text from a zipentry.

Feb 3, 2010 at 4:53 PM

Hi Cheeso

Just wondering if this is possible, i have a text file which is zipped in a zipfile.

I need to extract the text from the zipentry.

Are there any methods which would do that.



Feb 3, 2010 at 9:06 PM

ZipEntry.OpenReader will do it.

Feb 4, 2010 at 9:47 AM
Edited Feb 4, 2010 at 9:52 AM

Hi Cheeso

It returns a CrcCalculatorStream. I am wondering how to get the text/string from a zipentry.



Feb 4, 2010 at 12:08 PM

It's a stream;  you read all the bytes from the stream, then convert the bytes to a string using the encoding required.

For example

var stream = entry.OpenReader();
byte[] b = new byte[entry.UncompressedSize];
var string = System.Text.Encoding.ASCII.GetString(b);

You need to know which encoding to use.

If you prefer, you can Extract to a MemoryStream, something like this:

var ms = new MemoryStream();
var string = System.Text.Encoding.ASCII.GetString(ms.ToArray());

Feb 4, 2010 at 12:15 PM

Thanks Cheeso.