Function tskit::bindings::kastore_open

source ·
pub unsafe extern "C" fn kastore_open(
    self_: *mut kastore_t,
    filename: *const c_char,
    mode: *const c_char,
    flags: c_int
) -> c_int
Expand description

@brief Open a store from a given file in read (“r”), write (“w”) or append (“a”) mode.

@rst In read mode, a store can be queried using the :ref:get functions <sec_c_api_get> and any attempts to write to the store will return an error. In write and append mode, the store can written to using the :ref:put functions <sec_c_api_put> and any attempt to read will return an error.

After :c:func:kastore_open has been called on a particular store, :c:func:kastore_close must be called to avoid leaking memory. This must also be done when :c:func:kastore_open returns an error.

When opened in read-mode, the default is to read key/array values from file on demand. This is useful when a subset of the data is required and we don’t wish to read the entire file. If the entire file is to be read, the KAS_READ_ALL flag may be specified to improve performance.

Flags**

KAS_READ_ALL If this option is specified, read the entire file at open time. This will give slightly better performance as the file can be read sequentially in a single pass.

KAS_GET_TAKES_OWNERSHIP If this option is specified, all get operations will transfer ownership of the array to the caller. kastore will not free the array memory and this is the responsibility of the caller. If get is called on the same key multiple times, a new buffer will be returned each time. Note that second and subsequent get calls on a given key will result in seek operations even when the KAS_READ_ALL flag is set, and will therefore fail on unseekable streams.

@endrst

@param self A pointer to a kastore object. @param filename The file path to open. @param mode The open mode: can be read (“r”), write (“w”) or append (“a”). @param flags The open flags. @return Return 0 on success or a negative value on failure.