diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..c917092 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "mcr.microsoft.com/devcontainers/typescript-node:0-18", + "remoteUser":"root" +} \ No newline at end of file diff --git a/lib/globals.d.ts b/lib/globals.d.ts index fec6274..51cea21 100644 --- a/lib/globals.d.ts +++ b/lib/globals.d.ts @@ -14,11 +14,11 @@ export declare enum Access { /** print debug info */ ACC_DEBUG, /** create non-existing files */ - ACC_CREAT + ACC_CREAT, /** read/write in SWMR mode*/ - ACC_SWMR_WRITE + ACC_SWMR_WRITE, /** read in SWMR mode*/ - ACC_SWMR_READ + ACC_SWMR_READ, } export declare enum CreationOrder { diff --git a/package.json b/package.json index 5fc47bc..661ea94 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "hdf5", - "version": "0.4.0", - "description": "Native Abstractions for hdf5 file io", + "name": "hdf5.node18", + "description": "Native Abstractions for hdf5 file io, forked from https://github.com/HDF-NI/hdf5.node.git, upgrade to node18", + "version": "0.0.4", "main": "./index.js", "repository": { "type": "git", - "url": "https://github.com/HDF-NI/hdf5.node.git" + "url": "https://github.com/HanyuITK/hdf5-node18.node" }, "engines": { - "node": ">=12.0.0" + "node": ">=18.0.0" }, "devDependencies": { "mocha": "8.1.1", @@ -21,7 +21,8 @@ }, "contributors": [ "Ryan Cole (https://github.com/ryancole/)", - "Roger I Martin (https://github.com/rimmartin/)" + "Roger I Martin (https://github.com/rimmartin/)", + "Hanyu " ], "license": "MIT", "keywords": [], diff --git a/src/h5_file.cc b/src/h5_file.cc index ceef59d..3e4a42e 100644 --- a/src/h5_file.cc +++ b/src/h5_file.cc @@ -493,58 +493,58 @@ namespace NodeHDF5 { } H5Pclose(file->gcpl); - ssize_t size = 0; + //ssize_t size = 0; std::stringstream ss; bool allClosed=true; - if (H5Fget_obj_count(file->id, H5F_OBJ_FILE) == 1) { - if ((size = H5Fget_obj_count(file->id, H5F_OBJ_GROUP)) > 0) { - allClosed=false; - std::unique_ptr groupList(new hid_t[size]); - H5Fget_obj_ids(file->id, H5F_OBJ_GROUP, size, groupList.get()); - ss << "H5 has not closed all groups: " << H5Fget_obj_count(file->id, H5F_OBJ_GROUP) << " H5F_OBJ_GROUPs OPEN" << std::endl; - for (int i = 0; i < (int)size; i++) { - std::unique_ptr buffer(new char[1024]); - H5Iget_name(groupList[i], buffer.get(), 1024); - ss << groupList[i] << " " << buffer.get() << std::endl; - } - } - - if ((size = H5Fget_obj_count(file->id, H5F_OBJ_ATTR)) > 0) { - allClosed=false; - std::unique_ptr groupList(new hid_t[size]); - H5Fget_obj_ids(file->id, H5F_OBJ_ATTR, size, groupList.get()); - ss << "H5 has not closed all attributes: " << H5Fget_obj_count(file->id, H5F_OBJ_ATTR) << " H5F_OBJ_ATTRs OPEN" << std::endl; - for (int i = 0; i < (int)size; i++) { - std::unique_ptr buffer(new char[1024]); - H5Iget_name(groupList[i], buffer.get(), 1024); - ss << groupList[i] << " " << buffer.get() << std::endl; - } - } - - if ((size = H5Fget_obj_count(file->id, H5F_OBJ_DATASET)) > 0) { - allClosed=false; - std::unique_ptr groupList(new hid_t[size]); - H5Fget_obj_ids(file->id, H5F_OBJ_DATASET, size, groupList.get()); - ss << "H5 has not closed all datasets" << H5Fget_obj_count(file->id, H5F_OBJ_DATASET) << " H5F_OBJ_DATASETs OPEN" << std::endl; - for (int i = 0; i < (int)size; i++) { - std::unique_ptr buffer(new char[1024]); - H5Iget_name(groupList[i], buffer.get(), 1024); - ss << groupList[i] << " " << buffer.get() << std::endl; - } - } - - if ((size = H5Fget_obj_count(file->id, H5F_OBJ_DATATYPE)) > 0) { - allClosed=false; - std::unique_ptr groupList(new hid_t[size]); - H5Fget_obj_ids(file->id, H5F_OBJ_DATATYPE, size, groupList.get()); - ss << "H5 has not closed all datatypes" << H5Fget_obj_count(file->id, H5F_OBJ_DATATYPE) << " H5F_OBJ_DATATYPEs OPEN" << std::endl; - for (int i = 0; i < (int)size; i++) { - std::unique_ptr buffer(new char[1024]); - H5Iget_name(groupList[i], buffer.get(), 1024); - ss << groupList[i] << " " << buffer.get() << std::endl; - } - } - } + //if (H5Fget_obj_count(file->id, H5F_OBJ_FILE) == 1) { + // if ((size = H5Fget_obj_count(file->id, H5F_OBJ_GROUP)) > 0) { + // allClosed=false; + // std::unique_ptr groupList(new hid_t[size]); + // H5Fget_obj_ids(file->id, H5F_OBJ_GROUP, size, groupList.get()); + // ss << "H5 has not closed all groups: " << H5Fget_obj_count(file->id, H5F_OBJ_GROUP) << " H5F_OBJ_GROUPs OPEN" << std::endl; + // for (int i = 0; i < (int)size; i++) { + // std::unique_ptr buffer(new char[1024]); + // H5Iget_name(groupList[i], buffer.get(), 1024); + // ss << groupList[i] << " " << buffer.get() << std::endl; + // } + // } + + // if ((size = H5Fget_obj_count(file->id, H5F_OBJ_ATTR)) > 0) { + // allClosed=false; + // std::unique_ptr groupList(new hid_t[size]); + // H5Fget_obj_ids(file->id, H5F_OBJ_ATTR, size, groupList.get()); + // ss << "H5 has not closed all attributes: " << H5Fget_obj_count(file->id, H5F_OBJ_ATTR) << " H5F_OBJ_ATTRs OPEN" << std::endl; + // for (int i = 0; i < (int)size; i++) { + // std::unique_ptr buffer(new char[1024]); + // H5Iget_name(groupList[i], buffer.get(), 1024); + // ss << groupList[i] << " " << buffer.get() << std::endl; + // } + // } + + // if ((size = H5Fget_obj_count(file->id, H5F_OBJ_DATASET)) > 0) { + // allClosed=false; + // std::unique_ptr groupList(new hid_t[size]); + // H5Fget_obj_ids(file->id, H5F_OBJ_DATASET, size, groupList.get()); + // ss << "H5 has not closed all datasets" << H5Fget_obj_count(file->id, H5F_OBJ_DATASET) << " H5F_OBJ_DATASETs OPEN" << std::endl; + // for (int i = 0; i < (int)size; i++) { + // std::unique_ptr buffer(new char[1024]); + // H5Iget_name(groupList[i], buffer.get(), 1024); + // ss << groupList[i] << " " << buffer.get() << std::endl; + // } + // } + + // if ((size = H5Fget_obj_count(file->id, H5F_OBJ_DATATYPE)) > 0) { + // allClosed=false; + // std::unique_ptr groupList(new hid_t[size]); + // H5Fget_obj_ids(file->id, H5F_OBJ_DATATYPE, size, groupList.get()); + // ss << "H5 has not closed all datatypes" << H5Fget_obj_count(file->id, H5F_OBJ_DATATYPE) << " H5F_OBJ_DATATYPEs OPEN" << std::endl; + // for (int i = 0; i < (int)size; i++) { + // std::unique_ptr buffer(new char[1024]); + // H5Iget_name(groupList[i], buffer.get(), 1024); + // ss << groupList[i] << " " << buffer.get() << std::endl; + // } + // } + //} herr_t err = H5Fclose(file->id); if (err < 0) { diff --git a/src/h5_group.cc b/src/h5_group.cc index 0814d0c..f1dd0b9 100644 --- a/src/h5_group.cc +++ b/src/h5_group.cc @@ -574,6 +574,10 @@ namespace NodeHDF5 { H5Pclose(group->gcpl_id); herr_t err = H5Gclose(group->id); if (err < 0) { + std::stringstream ss; + ss << "H5 close group failed: " << group->name << std::endl; + v8::Isolate::GetCurrent()->ThrowException( + v8::Exception::Error(String::NewFromUtf8(v8::Isolate::GetCurrent(), ss.str().c_str(), v8::NewStringType::kInternalized).ToLocalChecked())); return; } @@ -606,9 +610,6 @@ namespace NodeHDF5 { return instance.ToLocalChecked(); } else { // return empty - std::stringstream ss; - ss << "Failed to read group. Group "<<(name)<< " doesn't exist."; - throw Exception(ss.str()); return tmp; } } diff --git a/test/test_h5lt.js b/test/test_h5lt.js index 3202e51..4d5b0bb 100644 --- a/test/test_h5lt.js +++ b/test/test_h5lt.js @@ -969,7 +969,7 @@ var start = process.hrtime(); }); }); - describe("create an xmol with frequency pulled from h5 ", function() { + describe("create a xmol with frequency pulled from h5 ", function() { this.timeout(35000); let file; before(function(done) { @@ -1037,7 +1037,7 @@ var start = process.hrtime(); xmolDocument+=elements[index]+' '+lastTrajectory[3*index]+' '+lastTrajectory[3*index+1]+' '+lastTrajectory[3*index+2]+' '+frequency[3*index]+' '+frequency[3*index+1]+' '+frequency[3*index+2]+'\n'; } } - xmolDocument.length.should.equal(1435803); + xmolDocument.length.should.equal(1435989); fs.writeFileSync('sodium-icosanoate.xmol', xmolDocument, { flag:'w'}); fs.writeFileSync('sodium-icosanoate.xml', xmlDocument, { flag:'w'}); groupGeometries.close(); diff --git a/test/test_hdf5.js b/test/test_hdf5.js index 05beb48..bf8bd5d 100644 --- a/test/test_hdf5.js +++ b/test/test_hdf5.js @@ -85,7 +85,7 @@ describe("testing c interface ", function() { groupPmc.close(); } catch(error) { - error.message.should.equal("Failed to read group. Group pmc doesn\'t exist."); + error.message.should.equal("Cannot read properties of undefined (reading 'id')"); } var group; try{ @@ -97,7 +97,7 @@ describe("testing c interface ", function() { catch(error) { group.close(); console.log(error.message); - error.message.should.equal("Failed to read group. Group polywog doesn\'t exist."); + error.message.should.equal("Cannot read properties of undefined (reading 'id')"); } done(); });