Reading an OCCI BLOB in C++

Example of how to read an OCCI Blob after retrieving it from the database.

CString fileName = "OutFile.bin";
int size;
FILE *destFile;
Blob blob;

// You'll need to make a database call here to populate the blob

fopen( &destFile, fileName, "wb" );
std::vector< BYTE > buffer( blob.getChunkSize() );
Stream *stream = blob.getStream();
 
if( destFile != NULL )
{
 
  while ( -1 != ( size = stream->readBuffer( ( char * ) &buffer[0], buffer.size() ) ) )
  {
    fwrite( ( char * ) &buffer[0], 1, size, destFile );
  }
 
blob.closeStream( stream );
fclose( destFile );
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s