Library Version 12.1.6.2

DB_STREAM->write()
Prev | Chapter 13. External Files | Next

## DB_STREAM->write()

    #include <db.h>

    int
    DB_STREAM->write(DB_STREAM *dbs, DBT *data, db_off_t offset,
                     u_int32_t flags);

The `DB_STREAM->write()` method writes data to an existing external file object in the database. This method writes data contained in the DBT data to the external file 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 external file, it will overwrite existing data, instead of shifting it. If this method writes data to the end of the external file, the data is appended to the existing external file. You can determine how large an external file is using DB_STREAM->size().

To open a stream, use DBC->db_stream().

Unless otherwise specified, the `DB_STREAM->write()` method returns a non-zero error value on failure and 0 on success.

### Parameters

#### data

The data parameter is the DBT containing the data to be written to the external file. The amount of data to be written is determined by the DBT's `size` field.

#### offset

The offset parameter identifies the position in the external file 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 DB_STREAM->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 `DB_STREAM->write()` method may fail and 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

DB_STREAM

### See Also

External Files and Related Methods

Prev | Up | Next
DB_STREAM->size() | Home | DB_ENV->get_ext_file_dir()