SharpZipLib in memory?

G

Guest

I know this is a horse that's been beated good and dead, but I *still* can't
find a good solution to this. I suppose I should post this on SharpZipLib's
forums, but I signed up and they never sent me a confirmation email, and I
can't resign up with the same email address. Great.

I'm trying to unzip from a byte array to a byte array using SharpZipLib.
Consider the following C# code:

MemoryStream msIn = new MemoryStream(bFile, 0, iSize);
GZipInputStream isZip = new GZipInputStream(msIn);

MemoryStream msOut = new MemoryStream();
byte[] buf = new byte[2048];
int size = 0;
while(true)
{
size = isZip.Read(buf, 0, 2048); //Fails here.
if (size > 0)
msOut.Write(buf, 0, size);
else
break;
}
isZip.Close();
return(msOut.ToArray());

I've tried a dozen different ideas posted on message boards all over the
internet, and none of them have worked. The code above comes almost directly
from the documentation (changed to read from a memorystream instead of a file
stream), but it doesn't work. I'm pulling my hair out.

Has anyone actually *done* this?



~BenDilts( void );
 
J

Jon Skeet [C# MVP]

BeanDog said:
I know this is a horse that's been beated good and dead, but I *still* can't
find a good solution to this. I suppose I should post this on SharpZipLib's
forums, but I signed up and they never sent me a confirmation email, and I
can't resign up with the same email address. Great.

I'm trying to unzip from a byte array to a byte array using SharpZipLib.
Consider the following C# code:

MemoryStream msIn = new MemoryStream(bFile, 0, iSize);
GZipInputStream isZip = new GZipInputStream(msIn);

MemoryStream msOut = new MemoryStream();
byte[] buf = new byte[2048];
int size = 0;
while(true)
{
size = isZip.Read(buf, 0, 2048); //Fails here.
if (size > 0)
msOut.Write(buf, 0, size);
else
break;
}
isZip.Close();
return(msOut.ToArray());

I've tried a dozen different ideas posted on message boards all over the
internet, and none of them have worked. The code above comes almost directly
from the documentation (changed to read from a memorystream instead of a file
stream), but it doesn't work. I'm pulling my hair out.

Has anyone actually *done* this?

That looks like it should be okay to me - except you haven't shown
where you're actually populating bFile to start with.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top