Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > GZipStream and decompression
 

GZipStream and decompression

I have code that should do the compression:

            FileStream fs = new
 FileStream("g:\\gj.txt"
, FileMode.Open);
            FileStream fd = new
 FileStream("g:\\gj.zip"
, FileMode.Create);
            GZipStream csStream = new
 GZipStream(fd, CompressionMode.Compress);


            byte
[] compressedBuffer = new
 byte
[500];
            int
 offset = 0;
            int
 nRead;

            nRead = fs.Read(compressedBuffer, offset, compressedBuffer.Length);
            while
 (nRead > 0)
            {
                csStream.Write(compressedBuffer, offset, nRead);
                if (nRead < compressedBuffer.Length) break;
offset = offset + nRead; nRead = fs.Read(compressedBuffer, offset, compressedBuffer.Length); } fd.Close(); fs.Close();
and I think it does, but I want to decompress what was compressed the way above. I do somethink like that:

            FileStream fd = new
 FileStream("g:\\gj.new"
, FileMode.Create);
            FileStream fs = new
 FileStream("g:\\gj.zip"
, FileMode.Open);
            GZipStream csStream = new
 GZipStream(fs, CompressionMode.Decompress);

            byte
[] decompressedBuffer = new
 byte
[500];
            int
 offset = 0;
            int
 nRead;

            nRead=csStream.Read(decompressedBuffer, offset, decompressedBuffer.Length);
            while
 (nRead > 0)
            {
                fd.Write(decompressedBuffer, offset, nRead);
                offset = offset + nRead;
                nRead = csStream.Read(decompressedBuffer, offset, decompressedBuffer.Length);
            }

            fd.Close();
            fs.Close();
and here it doesn't... I've got nRead = 0 befeore entering the loop... What I do wrong??
The test file I use is the simpliest TEXT file (size: 104 bytes)...
Jacek Szarapa  Saturday, October 17, 2009 7:54 AM
Your code would be easier to read if you formated it in the posting window with the </> button .
coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
Please format the code in your posts with the button . Makes it easier to read .
bdbodger  Saturday, October 17, 2009 8:12 PM

You can use google to search for other answers

Custom Search

More Threads

• How do you Convert Bytes?
• How can I get the timer to work?
• Add New Records.
• 32 vs 64 bits program in VB Express
• Updating records
• Intellectual Question??
• Classes Inheritance and Lists
• Form Help
• Print datagridview column names
• hello again