diff --git a/src/HDF5.jl b/src/HDF5.jl index 5a48dd84c..0d3945dd7 100644 --- a/src/HDF5.jl +++ b/src/HDF5.jl @@ -8,7 +8,7 @@ using Compat: unsafe_convert, String import Base: ==, close, convert, done, dump, eltype, endof, flush, getindex, isempty, isvalid, length, names, ndims, next, parent, read, - setindex!, show, size, sizeof, start, write + setindex!, show, size, sizeof, start, write, isopen export # types @@ -690,6 +690,13 @@ function close(obj::HDF5File) nothing end +""" + isopen(obj::HDF5File) + +Returns `true` if `obj` has not been closed, `false` if it has been closed. +""" +isopen(obj::HDF5File) = obj.id != -1 + for (h5type, h5func) in ((:(Union{HDF5Group, HDF5Dataset}), :h5o_close), (:HDF5Attribute, :h5a_close)) diff --git a/test/plain.jl b/test/plain.jl index e67934854..ac90bd796 100644 --- a/test/plain.jl +++ b/test/plain.jl @@ -10,6 +10,7 @@ using Compat.String # Create a new file fn = joinpath(tempdir(),"test.h5") f = h5open(fn, "w") + @test isopen(f) # Write scalars f["Float64"] = 3.2 f["Int16"] = Int16(4) @@ -107,6 +108,7 @@ using Compat.String # Create a dataset designed to be deleted f["deleteme"] = 17.2 close(f) + @test !isopen(f) # Test the h5read/write interface, with attributes W = copy(reshape(1:120, 15, 8)) Wa = Dict("a"=>1, "b"=>2)