Page tree


Can you store a binary object (for example, a Word document ) in an HDF5 file?

Yes. You can store your file in a dataset with an opaque datatype, in which the opaque datatype's tag is set to the MIME type of the file, with a prefix of "Content-Type":

    Content-Type: <mime-type> 

Storing the file as a dataset with an opaque datatype will prevent datatype conversions from occurring when reading or writing. Putting the mime-type in the tag, with the "Content-Type:" prefix, gives users a standard place to look for the mime-type (and mimics the prefix that email headers use for storing the mime-type).

Another way to do this is to store the file in the user block. The user block is a user definable data block at the beginning of an HDF5 file, which HDF5 ignores. There are utilities (h5jam, h5unjam) for writing to and extracting information from the user block. Also see the H5Pset_userblock API for creating a user block from within an application.