Apache OpenDALâ„¢ C Binding
The C binding for Apache OpenDALâ„¢
Loading...
Searching...
No Matches
opendal_write_options Struct Reference

Options for write operations. More...

#include <opendal.h>

Public Attributes

bool append
const char * cache_control
const char * content_type
const char * content_disposition
const char * content_encoding
const char * if_match
const char * if_none_match
bool if_not_exists
uintptr_t concurrent
bool has_chunk
uintptr_t chunk
const struct opendal_write_user_metadata_pair * user_metadata
uintptr_t user_metadata_len

Detailed Description

Options for write operations.

Each condition checks the file currently stored at the write path, and the service evaluates it atomically with the write's visible commit:

See the conditional operation specification for the complete cross-operation contract.

Use opendal_write_options_new() to construct and opendal_write_options_free() to free.

A caller that declares the struct itself must initialize every member, for example with opendal_write_options opts = {0};, because a function that takes these options reads every member, also one whose has_* member is false.

See also
opendal_operator_write_with
opendal_write_options_new
opendal_write_options_free
opendal_write_options_set_append
opendal_write_options_set_cache_control
opendal_write_options_set_content_type
opendal_write_options_set_content_disposition
opendal_write_options_set_content_encoding
opendal_write_options_set_if_match
opendal_write_options_set_if_none_match
opendal_write_options_set_if_not_exists
opendal_write_options_set_concurrent
opendal_write_options_set_chunk
opendal_write_options_set_user_metadata

Member Data Documentation

◆ append

bool opendal_write_options::append

Sets append mode for this operation.

Capability

Check opendal_capability.write_can_append before using this option.

Behavior

  • By default, write operations overwrite existing files
  • When append is set to true:
    • New data will be appended to the end of existing file
    • If file doesn't exist, it will be created
  • If not supported, will return an error

This operation allows adding data to existing files instead of overwriting them.

◆ cache_control

const char* opendal_write_options::cache_control

Sets Cache-Control header for this write operation.

Capability

Check opendal_capability.write_with_cache_control before using this feature.

Behavior

  • If supported, sets Cache-Control as system metadata on the target file
  • The value should follow HTTP Cache-Control header format
  • If not supported, the value will be ignored

This operation allows controlling caching behavior for the written content.

Use Cases

  • Setting browser cache duration
  • Configuring CDN behavior
  • Optimizing content delivery
  • Managing cache invalidation

References

NULL means unset. A non-NULL value must point to a readable, nul-terminated UTF-8 string. opendal_write_options_set_cache_control() stores this pointer without copying the string, and opendal_write_options_free() does not free it, so the string must stay valid until the function that takes these options returns.

◆ chunk

uintptr_t opendal_write_options::chunk

Sets chunk size for buffered writes.

Capability

Check opendal_capability.write_multi_min_size and opendal_capability.write_multi_max_size for size limits.

Behavior

  • By default, OpenDAL buffers data until it reaches the service's opendal_capability.write_multi_min_size and then writes everything buffered at once; a service without that minimum receives each write as it arrives
  • 0 has the same behavior as leaving it unset
  • When chunk size is set:
    • Data will be buffered until reaching chunk size
    • Each chunk reaches the service writer as one write; a service may add requests, such as the ones that start and complete an S3 multipart upload
    • Last chunk may be smaller than chunk size
  • Important considerations:

Performance Impact

Setting appropriate chunk size can:

  • Reduce number of API calls
  • Improve overall throughput
  • Lower operation costs
  • Better utilize network bandwidth

has_chunk controls whether this value applies.

◆ concurrent

uintptr_t opendal_write_options::concurrent

Sets concurrent write operations for this writer.

Behavior

  • By default, OpenDAL writes files sequentially
  • 0 has the same behavior as 1
  • When concurrent is greater than 1:
    • Multiple write operations can execute in parallel
    • Write operations return immediately without waiting if tasks space are available
    • Close operation ensures all writes complete in order
    • Memory usage increases with concurrency level
  • If not supported, falls back to sequential writes

opendal_operator_write_with() without chunk passes the whole buffer to the service writer as one write. A service that splits the buffer internally, such as fs with direct_io on Linux, can write the parts concurrently.

This feature significantly improves performance when:

  • Writing large files
  • Network latency is high
  • Storage service supports concurrent uploads like multipart uploads

Performance Impact

Setting appropriate concurrency can:

  • Increase write throughput
  • Reduce total write time
  • Better utilize available bandwidth
  • Trade memory for performance

0 is the default.

◆ content_disposition

const char* opendal_write_options::content_disposition

Sets Content-Disposition header for this write request.

Capability

Check opendal_capability.write_with_content_disposition before using this feature.

Behavior

  • If supported, sets Content-Disposition as system metadata on the target file
  • The value should follow HTTP Content-Disposition header format
  • Common values include:
    • inline - Content displayed within browser
    • attachment - Content downloaded as file
    • attachment; filename="example.jpg" - Downloaded with specified filename
  • If not supported, the value will be ignored

This operation allows controlling how the content should be displayed or downloaded.

NULL means unset. A non-NULL value must point to a readable, nul-terminated UTF-8 string. opendal_write_options_set_content_disposition() stores this pointer without copying the string, and opendal_write_options_free() does not free it, so the string must stay valid until the function that takes these options returns.

◆ content_encoding

const char* opendal_write_options::content_encoding

Sets Content-Encoding header for this write request.

Capability

Check opendal_capability.write_with_content_encoding before using this feature.

Behavior

  • If supported, sets Content-Encoding as system metadata on the target file
  • The value should follow HTTP Content-Encoding header format
  • Common values include:
    • gzip - Content encoded using gzip compression
    • deflate - Content encoded using deflate compression
    • br - Content encoded using Brotli compression
    • identity - No encoding applied (default value)
  • If not supported, the value will be ignored

This operation allows specifying the encoding applied to the content being written.

NULL means unset. A non-NULL value must point to a readable, nul-terminated UTF-8 string. opendal_write_options_set_content_encoding() stores this pointer without copying the string, and opendal_write_options_free() does not free it, so the string must stay valid until the function that takes these options returns.

◆ content_type

const char* opendal_write_options::content_type

Sets Content-Type header for this write operation.

Capability

Check opendal_capability.write_with_content_type before using this feature.

Behavior

  • If supported, sets Content-Type as system metadata on the target file
  • The value should follow MIME type format (e.g. "text/plain", "image/jpeg")
  • If not supported, the value will be ignored

This operation allows specifying the media type of the content being written.

NULL means unset. A non-NULL value must point to a readable, nul-terminated UTF-8 string. opendal_write_options_set_content_type() stores this pointer without copying the string, and opendal_write_options_free() does not free it, so the string must stay valid until the function that takes these options returns.

◆ has_chunk

bool opendal_write_options::has_chunk

Whether chunk has been set.

◆ if_match

const char* opendal_write_options::if_match

Write only when the file at the write path has this exact ETag.

The condition succeeds when the file exists and its ETag equals this value. A file with a different ETag, or a missing file, fails the write with OPENDAL_CONDITION_NOT_MATCH. Only concrete ETag values are portable; a wildcard such as "*" has no portable meaning here.

The operation returns OPENDAL_UNSUPPORTED when the service does not advertise opendal_capability.write_with_if_match.

NULL means unset. A non-NULL value must point to a readable, nul-terminated UTF-8 string. opendal_write_options_set_if_match() stores this pointer without copying the string, and opendal_write_options_free() does not free it, so the string must stay valid until the function that takes these options returns.

◆ if_none_match

const char* opendal_write_options::if_none_match

Write only when the file at the write path does not have this ETag.

With a concrete ETag value, the condition succeeds when the file has a different ETag or does not exist; the write then replaces or creates the file. A file whose ETag equals this value fails the write with OPENDAL_CONDITION_NOT_MATCH. Only concrete ETag values are portable; a wildcard such as "*" has no portable meaning here.

The operation returns OPENDAL_UNSUPPORTED when the service does not advertise opendal_capability.write_with_if_none_match. Some services, such as s3, support if_not_exists but not if_none_match; use if_not_exists when you only need to guard against an existing file.

NULL means unset. A non-NULL value must point to a readable, nul-terminated UTF-8 string. opendal_write_options_set_if_none_match() stores this pointer without copying the string, and opendal_write_options_free() does not free it, so the string must stay valid until the function that takes these options returns.

◆ if_not_exists

bool opendal_write_options::if_not_exists

Write only when no file exists at the write path.

The condition succeeds when the path is empty, so the write creates the file. An existing file fails the write with OPENDAL_CONDITION_NOT_MATCH.

The operation returns OPENDAL_UNSUPPORTED when the service does not advertise opendal_capability.write_with_if_not_exists.

◆ user_metadata

const struct opendal_write_user_metadata_pair* opendal_write_options::user_metadata

Sets user metadata for this write request.

Capability

Check opendal_capability.write_with_user_metadata before using this feature.

Behavior

  • If supported, the user metadata will be attached to the object during write
  • Accepts key-value pairs where both key and value are strings
  • Some services, such as s3, return keys in lowercase
  • Services may have limitations for user metadata, for example:
    • Key length is typically limited (e.g., 1024 bytes)
    • Value length is typically limited (e.g., 4096 bytes)
    • Total metadata size might be limited
    • Some characters might be forbidden in keys
  • If not supported, the metadata will be ignored

User metadata provides a way to attach custom metadata to objects during write operations. When the service exposes user metadata, opendal_metadata_get_user_metadata() on the result of a later opendal_operator_stat() returns it.

NULL or a user_metadata_len of 0 means unset. opendal_write_options_set_user_metadata() stores this pointer without copying the pairs or their strings, and opendal_write_options_free() does not free them, so they must stay valid until the function that takes these options returns. A pair whose key or value is NULL is skipped, and a later pair replaces an earlier pair with the same key.

◆ user_metadata_len

uintptr_t opendal_write_options::user_metadata_len

The number of pairs at user_metadata.


The documentation for this struct was generated from the following file: