Skip to content

Commit 65707f5

Browse files
committed
Add chunking/compression
1 parent 7c41472 commit 65707f5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

include/binsparse/hdf5_wrapper.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ int bsp_write_array(hid_t f, char* label, bsp_array_t array) {
1616
hid_t fspace = H5Screate_simple(1, (hsize_t[]){array.size}, NULL);
1717
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
1818

19-
hid_t dset = H5Dcreate2(f, label, hdf5_standard_type, fspace, lcpl,
20-
H5P_DEFAULT, H5P_DEFAULT);
19+
hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
20+
21+
// Choose 1 MiB, the default chunk cache size, as our chunk size.
22+
size_t chunk_size = 1024 * 1024 / bsp_type_size(array.type);
23+
24+
// If the dataset is smaller than the chunk size, cap the chunk size.
25+
if (array.size < chunk_size) {
26+
chunk_size = array.size;
27+
}
28+
29+
H5Pset_chunk(dcpl, 1, (hsize_t[]){chunk_size});
30+
31+
H5Pset_deflate(dcpl, 9);
32+
33+
hid_t dset =
34+
H5Dcreate2(f, label, hdf5_standard_type, fspace, lcpl, dcpl, H5P_DEFAULT);
2135

2236
if (dset == H5I_INVALID_HID) {
2337
return -1;
@@ -34,6 +48,7 @@ int bsp_write_array(hid_t f, char* label, bsp_array_t array) {
3448

3549
H5Sclose(fspace);
3650
H5Pclose(lcpl);
51+
H5Pclose(dcpl);
3752

3853
return 0;
3954
}

0 commit comments

Comments
 (0)