def save_to_filenode(h5file, filename, where, name=None, overwrite=False,
                     title="", filters=None):
    # sanity checks
    if not os.access(filename, os.R_OK):
        raise IOError("The file '%s' could not be read" % filename)
    if isinstance(h5file, tables.file.File) and h5file.mode == "r":
        raise IOError("The file '%s' is opened read-only" % h5file.filename)

    # guess filenode's name if necessary
    if name is None:
        if isinstance(where, tables.group.Group):
            name = os.path.split(filename)[1]
        if isinstance(where, string_types):
            if where.endswith("/"):
                name = os.path.split(filename)[1]
            else:
                nodepath = where.split("/")
                where = "/" + "/".join(nodepath[:-1])
                name = nodepath[-1]

    # sanitize name if necessary
    if not tables.path._python_id_re.match(name):
        name = re.sub('(?![a-zA-Z0-9_]).', "_",
                      re.sub('^(?![a-zA-Z_]).', "_", name))

    new_h5file = not isinstance(h5file, tables.file.File)
    f = tables.File(h5file, "a") if new_h5file else h5file

    # check for already existing filenode
    try:
        n = f.get_node(where=where, name=name)
        if not overwrite:
            if new_h5file:
                f.close()
            raise IOError("Specified node already exists in file '%s'" %
                          f.filename)
    except tables.NoSuchNodeError:
        pass

    # read data from disk
    with open(filename, "rb") as fd:
        data = fd.read()

    # remove existing filenode if present
    try:
        f.remove_node(where=where, name=name)
    except tables.NoSuchNodeError:
        pass

    # write file's contents to filenode
    fnode = new_node(f, where=where, name=name, title=title, filters=filters)
    fnode.write(data)
    fnode.attrs._filename = os.path.split(filename)[1]
    fnode.close()

    # cleanup
    if new_h5file:
        f.close()
Save a file's contents to a filenode inside a PyTables file.
dataset/ETHPy150Open PyTables/PyTables/tables/nodes/filenode.py/save_to_filenode