Skip to content
Snippets Groups Projects
Commit d3fbe78e authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Bugfix: setting streamfile source now closes previous hdf5 file and re-reads...

Bugfix: setting streamfile source now closes previous hdf5 file and re-reads metadata only if they are defined
parent b9899fae
No related branches found
No related tags found
1 merge request!22Draft: Implements metadata handling for bob.io.stream.Stream and bob.io.stream.StreamFile
Pipeline #59858 passed
......@@ -122,15 +122,18 @@ class StreamFile:
"""
if hdf5_file is not None:
self.hdf5_file_path = hdf5_file
if self.hdf5_file is not None: # close file if open
self.hdf5_file.close()
self.hdf5_file = h5py.File(hdf5_file, mode)
if metadata is not None:
self._metadata = metadata
# we read the file, or we append to an already existing file and want to keep the file's metadata
if mode == "r" or (mode == "a" and not overwrite_metadata):
self.read_metadata()
# we write a new file, or append to an existing file but want to overwrite the file's metadata.
elif mode == "w" or (mode == "a" and overwrite_metadata):
self.write_metadata()
if metadata is not None:
self._metadata = metadata
# we read the file, or we append to an already existing file and want to keep the file's metadata
if mode == "r" or (mode == "a" and not overwrite_metadata):
self.read_metadata()
# we write a new file, or append to an existing file but want to overwrite the file's metadata.
elif mode == "w" or (mode == "a" and overwrite_metadata):
self.write_metadata()
def read_metadata(self):
"""Read the metadata values from the hdf5 file and store them in `self._metadata`."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment