You are here: Advanced Features > Type Handling > Blobs > Db4o Blob Implementation

Db4o Blob Implementation

Built-in db4o blob type helps you to get rid of the problems of byte[] array, though it has its own drawbacks.

  1. Every Blob gets it's own file:
  2. + Main database file stays a lot smaller.

    + Backups are possible over individual files.

    +The BLOBs are accessible without db4o.

    - Multiple files need to be managed .

  1. Special code is necessary to store and load.
  2. - It is more difficult to move objects between db4o database files.

  3. No concerns about activation depth
  4. + Big objects won't be loaded into memory as part of the activation process.

Configuration

First, the blob storage location should be defined. If that value is not defined, db4o will use the default folder "blobs" in user directory.

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.File.BlobPath = "myBlobDirectory";
FileConfiguration.cs: Configure the blob-path
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.File.BlobPath = "myBlobDirectory"
FileConfiguration.vb: Configure the blob-path

Using The db4o-Blob

There are two important operations on the blob type. The first one write a file into the db4o blob:

blob.ReadFrom(fileToStore);
BlobStorage.cs: Store the file as a db4o-blob
blob.ReadFrom(fileToStore)
BlobStorage.vb: Store the file as a db4o-blob

And then there's the operation which .loads the db4o blob into a new file.

blob.WriteTo(file);
BlobStorage.cs: Load a blob from a db4o-blob
blob.WriteTo(file)
BlobStorage.vb: Load a blob from a db4o-blob

The db4o blob-type has a status attached to it. This status tells you if the blob-file all ready has been transferred:

while (blob.GetStatus() > Status.Completed)
{
    Thread.Sleep(50);
}
BlobStorage.cs: wait until the operation is done
While blob.GetStatus() > Status.Completed
    Thread.Sleep(50)
End While
BlobStorage.vb: wait until the operation is done

Take a look a the complete example code (C#, VB.NET).