Skip to content

Commit

Permalink
Merge pull request #85 from axelboc/add-close
Browse files Browse the repository at this point in the history
Add `close_file` method to Module API
  • Loading branch information
bmaranville authored Sep 6, 2024
2 parents b5f5b71 + d05e0c0 commit 437b5c6
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_file` method to Module API: `close_file(file_id: bigint): number;`
### Fixed
- Fix accessing attributes of committed datatype with `my_datafile.attrs`.
- Fix calling `get_attribute_names` method of Module API on committed datatype.
Expand Down
2 changes: 1 addition & 1 deletion src/hdf5_hl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ export class File extends Group {
}

close(): Status {
return Module.ccall("H5Fclose", "number", ["bigint"], [this.file_id]);
return Module.close_file(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_file(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 @@ -1329,6 +1335,7 @@ int deactivate_throwing_error_handler() {
EMSCRIPTEN_BINDINGS(hdf5)
{
function("open", &open);
function("close_file", &close_file);
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(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 437b5c6

Please sign in to comment.