Skip to content

Commit

Permalink
add haskey(::FITS, key)
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin authored and cgarling committed Aug 24, 2024
1 parent 6d4a051 commit 36ca550
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/fits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 36ca550

Please sign in to comment.