Archived Forum Post

Index of archived forum posts

Question:

Directly ZIP a blobfile without having to save the BLOBfile to disk first

Jun 27 '12 at 07:27

I was wondering if it would be possible (in future versions?) to ZIP a BLOBfile without having to save the BLOBfile to disk, zipping the file, and saving the zipped file back to a BLOBfile. (and also the other way around, unzipping a BLOBfile)

this so save valuable time and resources ...


Accepted Answer

Something like this should work:

  1. Create a new ChilkatZip2 object
  2. Read the data from your database into a byte array.
  3. Use the ChilkatZip2.AppendData method to append the array to the new archive
  4. Use the ChilkatZip2.WriteToMemory method to retrieve the archive in a new Byte array.
  5. Call ChilkatZip2.CloseZip to clean up.
  6. Store the returned byte array of the zip file in your database.

Answer

I don't understand what a "BLOBfile" is, but I'm assuming it has to do with a binary field in a SQL Server database? In any case, the Chilkat Zip ActiveX (I assume if it's SQL Server, then you're using the ActiveX?), the Chilkat Zip API provides OpenFromMemory and WriteToMemory methods to read and write .zip archives from memory. Given this, the only task is to determine how to pass the binary data from a database field to an ActiveX method, and the reverse: how to save the returned binary data from an ActiveX to a database field.

I don't actually know the answer to that question. I may involve using a temp table as shown here for getting a long string property: http://www.example-code.com/sql/default.asp

However, in any programming language, NEVER treat binary data that does not represent actual characters as a string (i.e. never treat the binary output of encryption, or image data, or the binary data of a compressed file format such as a .zip as a string). The reason is that you never want anything to be trying to interpret those bytes as characters encoded according to some charset (such as utf-8, iso-8859-1, etc.) I say this because whatever the solution, it would involve a database field that is NOT a string, but must be something that represents binary data.


Answer

thanks for your answer.

a BLOB is a file (txt, xml, pdf, ...) stored in a database.

Now I have to convert the BLOB to a physical file on disk, zip it, and convert it back to a BLOB and store it in the database again. And this takes time ...


Answer

Works just great !! Just had a little trouble with the return of the WriteToMemory-method, but at the moment it works ...

Thanks a lot !!