Hi,
I'm trying to uncompress data from a binary field in a sql server 2000
database. I can currently write that data to a '.zip' file and use
the example program to read and uncompress it - so I know the data
itself is fine and that C1zip is capable of working on it.
When I try to uncompress it in a stream, I get 'Error inflating:
unknown compression method' - which is odd since it seems to work
just fine when used on a file generated from the field.
My knowledge of streams is small so I figured I'm doing something
wrong. Here's my code - please tell me where I'm screwing up.
rdrImage is a SqlData Reader
Compressed is a System.IO.MemoryStream
I'm basically trying to uncompress an image and then display it in
ASP.NET. The code works fine reading it straight out of the database
if the image isn't compressed. (Yes I know the jpgs shouldn't be
compressed - it wasn't my idea - I just have to deal with it)
int iSize = ( (byte[])rdrImage[ "mData" ] ).Length;
Compressed.Write( (byte[])rdrImage[ "mData" ], 0, iSize );
Compressed.Position = 0;
C1ZStreamReader sr = new C1ZStreamReader( Compressed );
// crashes here with above error iSize is correct at this point and
data has been written into Compressed.
Buffer = new byte[ iSize * 2 ];
int iFullSize = sr.Read( Buffer, 0, iSize * 2 );
Response.OutputStream.Write( Buffer, 0, iFullSize );
//Response.OutputStream.Write( (byte[])rdrImage[ "mData"
], 0, iSize );
Response.End();
As you can see I spend a lot of time moving it from byte[] to stream
and back - I suspect there is a better way to do this, but the stream
documentation is a bit lacking.
Regards,
Nick Hustak
Click here to view the original newsgroup article (read only).