Skip to content

Commit

Permalink
Add close method to Module API
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Sep 5, 2024
1 parent a7bc6b4 commit 8c52fbb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog
## v0.7.8 TBC
### Added
- Add `close` method to Module API: `close(file_id: bigint): number;`
### Changed
- Mark optional parameters as such in the TypeScript declarations of the following `H5Module` methods: `open`, `create_dataset`, `create_group`, `create_vlen_str_dataset` and `get_keys_vector`.
## v0.7.7 2024-08-28
Expand Down
2 changes: 1 addition & 1 deletion src/hdf5_hl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ export class File extends Group {
}

close(): Status {
return Module.ccall("H5Fclose", "number", ["bigint"], [this.file_id]);
return Module.close(this.file_id);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/hdf5_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ int64_t open(const std::string& filename_string, unsigned int h5_mode = H5F_ACC_
return (int64_t)file_id;
}

int close(hid_t file_id)
{
herr_t status = H5Fclose(file_id);
return (int)status;
}

herr_t link_name_callback(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata)
{
std::vector<std::string> *namelist = reinterpret_cast<std::vector<std::string> *>(opdata);
Expand Down Expand Up @@ -1325,6 +1331,7 @@ int deactivate_throwing_error_handler() {
EMSCRIPTEN_BINDINGS(hdf5)
{
function("open", &open);
function("close", &close);
function("get_keys", &get_keys_vector);
function("get_names", &get_child_names);
function("get_types", &get_child_types);
Expand Down
1 change: 1 addition & 0 deletions src/hdf5_util_helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface VirtualSource {

export interface H5Module extends EmscriptenModule {
open(filename: string, mode?: number, track_order?: boolean): bigint;
close(file_id: bigint): number;
create_dataset(file_id: bigint, arg1: string, arg2: bigint, shape: bigint[], maxshape: (bigint | null)[], chunks: bigint[] | null, type: number, size: number, signed: boolean, vlen: boolean, compression_id: number, compression_opts: number[], track_order?: boolean): number;
create_soft_link(file_id: bigint, link_target: string, link_name: string): number;
create_hard_link(file_id: bigint, link_target: string, link_name: string): number;
Expand Down

0 comments on commit 8c52fbb

Please sign in to comment.