diff --git a/docs/make.jl b/docs/make.jl index b9b5cfced..6c0f59dcf 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -40,7 +40,8 @@ makedocs(; "interface/dataset.md", "interface/attributes.md", "interface/properties.md", - "interface/filters.md" + "interface/filters.md", + "interface/objects.md", ], "mpi.md", "Low-level library bindings" => "api_bindings.md", diff --git a/docs/src/index.md b/docs/src/index.md index 023a0a316..c7e633fae 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -489,6 +489,13 @@ b[1:10000] = collect(1:10000) when dimensions are reduced, the truncated data is lost. A maximum dimension of -1 is often referred to as unlimited dimensions, though it is limited by the maximum size of an unsigned integer. +You can copy data from one file to another: + +```julia +copy_object(source, data_name, target, name) +copy_object(source[data_name], target, name) +``` + Finally, it's possible to delete objects: ```julia diff --git a/docs/src/interface/objects.md b/docs/src/interface/objects.md new file mode 100644 index 000000000..6135fd3de --- /dev/null +++ b/docs/src/interface/objects.md @@ -0,0 +1,10 @@ +# Objects + +```@meta +CurrentModule = HDF5 +``` + +```@docs +copy_object +delete_object +``` diff --git a/src/groups.jl b/src/groups.jl index 133baa502..7c98360cd 100644 --- a/src/groups.jl +++ b/src/groups.jl @@ -145,6 +145,17 @@ function Base.keys(x::Union{Group,File}) return children end +""" + delete_object(parent::Union{File,Group}, path::AbstractString) + +Delete the object at `parent[path]`. + +# Examples +```julia +f = h5open("f.h5", "r+") +delete_object(f, "Group1") +``` +""" delete_object( parent::Union{File,Group}, path::AbstractString, diff --git a/src/objects.jl b/src/objects.jl index 396685830..33aef75c0 100644 --- a/src/objects.jl +++ b/src/objects.jl @@ -45,6 +45,19 @@ function gettype(parent, path::AbstractString) end # Copy objects +""" + copy_object(src_parent::Union{File,Group}, src_path::AbstractString, dst_parent::Union{File,Group}, dst_path::AbstractString) + +Copy data from `src_parent[src_path]` to `dst_parent[dst_path]`. + +# Examples +```julia +f = h5open("f.h5", "r") +g = h5open("g.h5", "cw") +copy_object(f, "Group1", g, "GroupA") +copy_object(f["Group1"], "data1", g, "DataSet/data_1") +``` +""" copy_object( src_parent::Union{File,Group}, src_path::AbstractString, @@ -58,6 +71,15 @@ copy_object( API.H5P_DEFAULT, _link_properties(dst_path) ) +""" + copy_object(src_obj::Object, dst_parent::Union{File,Group}, dst_path::AbstractString) + +# Examples +```julia +copy_object(f["Group1"], g, "GroupA") +copy_object(f["Group1/data1"], g, "DataSet/data_1") +``` +""" copy_object(src_obj::Object, dst_parent::Union{File,Group}, dst_path::AbstractString) = API.h5o_copy( checkvalid(src_obj),