diff --git a/src/fits.jl b/src/fits.jl index cdcd14b..6a18350 100644 --- a/src/fits.jl +++ b/src/fits.jl @@ -125,6 +125,13 @@ function getindex(f::FITS, name::AbstractString, ver::Int=0) return f.hdus[i] end +Base.haskey(f::FITS, i::Integer) = i ∈ 1:length(f) + +Base.haskey(f::FITS, name::AbstractString) = any(1:length(f)) do i + fits_movabs_hdu(f.fitsfile, i) + fits_try_read_extname(f.fitsfile) == name +end + """ deleteat!(f::FITS, i::Integer) diff --git a/test/runtests.jl b/test/runtests.jl index aab8084..aba9011 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -403,6 +403,10 @@ end write(f, a, name="a") @test read(f["a"]) == a @test read(f[1]) == a + @test haskey(f, "a") + @test !haskey(f, "b") + @test haskey(f, 1) + @test !haskey(f, 2) end end end