diff --git a/Project.toml b/Project.toml index 606d87e..2f636b8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DICOM" uuid = "a26e6606-dd52-5f6a-a97f-4f611373d757" -version = "0.10.0" +version = "0.10.1" [compat] julia = "0.7, 1" diff --git a/src/DICOM.jl b/src/DICOM.jl index cfcc45a..64bf64a 100644 --- a/src/DICOM.jl +++ b/src/DICOM.jl @@ -136,8 +136,12 @@ function find_dicom_files(dir) end function isdicom(file) - bytes = read(file, 132)[end-3:end] - String(bytes) == "DICM" + all_bytes = read(file, 132) + if length(all_bytes) < 132 + return false + end + my_bytes = all_bytes[end-3:end] + return String(my_bytes) == "DICM" end function dcmdir_parse(dir; kwargs...) diff --git a/test/runtests.jl b/test/runtests.jl index 4fe4acb..42fd148 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -226,9 +226,21 @@ end @testset "Parse entire folder" begin # Following files have missing preamble and won't be parsed # ["OT_Implicit_Little_Headless.dcm", "CT_Implicit_Little_Headless_Retired.dcm"] + # along with an invalid notdicom.dcm file which we will first create + notdicomfile = joinpath(data_folder, "notdicom.dcm") + open(notdicomfile, "w") do io + print(io, "!") + end + + # First, test the isdicom() function + fileDX = download_dicom("DX_Implicit_Little_Interleaved.dcm") + @test DICOM.isdicom(fileDX) == true + @test DICOM.isdicom(notdicomfile) == false + + # Second, test if all valid dicom file can be parsed dcms = dcmdir_parse(data_folder) @test issorted([dcm[tag"Instance Number"] for dcm in dcms]) - @test length(dcms) == length(readdir(data_folder)) - 2 # -2 because of note above + @test length(dcms) == length(readdir(data_folder)) - 3 # -3 because of note above end @testset "Test tag macro" begin