This project is read-only.

Uncompress to Response.Write

May 3, 2011 at 2:51 PM

I need to allow visitors to download PDF files that are compressed and stored in an Oracle database as a BLOB.  I am trying to find a way to uncompress the data that I retrieve from the database and send it to directly to Response.Write instead of the file stream. 

Thanks in advance for any help.


May 7, 2011 at 2:41 PM

Sounds great; what exactly is the format in the Oracle db?  You said that they are "compressed" - but compressed how?  Are they ZIP files, stored in the column? 

I've seen other examples where there is ZIP data in a database, stored as base64, or just as a hex-encoded string.  If that's the case you will need to do a conversion from the in-database representation to a stream of bytes.

Supposing that you are able to get access to a readable stream from the database that supplies the stream of bytes that defines a zip file (not a gzip, not some other compression), then you could do something like this:

using (var zis = new ZipInputStream(databaseStream))
    byte[] buffer= new byte[2048];
    int n;
    ZipEntry e;
    while (( e = zis.GetNextEntry()) != null)
        if (e.FileName != "MyDesiredFile.pdf") continue;
        while ((n= input.Read(buffer, 0, buffer.Length)) > 0)