Library Version 12.1.6.0

DbStream::write()
Prev | Chapter 14. Binary Large Objects | Next

## DbStream::write()

    #include <db_cxx.h>

    int
    DbStream::write(Dbt *data, db_off_t offset, u_int32_t flags);

The `DbStream::write()` method writes data to an existing BLOB object in the database. This method writes data contained in the Dbt data to the BLOB stream. Data is written into the stream starting at the position indicated by offset. The amount of data written is determined by the `size` field in the Dbt.

If this method writes data in the middle of the BLOB, it will overwrite existing data, instead of shifting it. If this method writes data to the end of the BLOB, the data is appended to the existing BLOB. You can determine how large a BLOB is using DbStream::size().

To open a stream, use Dbc::db_stream().

Unless otherwise specified, the `DbStream::write()` method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

### Parameters

#### data

The data parameter is the Dbt containing the data to be written to the BLOB. The amount of data to be written is determined by the Dbt's `size` field.

#### offset

The offset parameter identifies the position in the BLOB where the write operation will begin.

#### flags

The flags parameter must be set to 0 or the following value:

- `DB_STREAM_SYNC_WRITE`

  A sync to disk operation is performed on the stream at the end of the write operation. By default, the sync is performed only when the stream is closed using DbStream::close(). Note that this flag can also be specified when the stream is created using Dbc::db_stream(), in which case the sync behavior becomes the default behavior for this stream instance.

### Errors

The `DbStream::write()` method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

#### EINVAL

An invalid flag value or parameter was specified; or if the stream is read-only; or if the input Dbt was configured with DB_DBT_PARTIAL.

### Class

DbStream

### See Also

BLOBs and Related Methods

Prev | Up | Next
DbStream::size() | Home | DbEnv::get_blob_dir()