Skip to content

Commit

Permalink
Add zip_test (#73)
Browse files Browse the repository at this point in the history
* Export `zip_test`

* fix docs typo
  • Loading branch information
nhz2 authored Sep 1, 2024
1 parent 45d03bc commit 3dcffe9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ZipArchives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export zip_general_purpose_bit_flag
export zip_entry_data_offset

export zip_test_entry
export zip_test
export zip_openentry
export zip_readentry

Expand Down
16 changes: 16 additions & 0 deletions src/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,22 @@ function zip_test_entry(r::ZipReader, i::Integer)::Nothing
nothing
end

"""
zip_test(r::ZipReader)::Nothing
Test all entries in the archive in order from `1` to `zip_nentries(r)`
Throw an error for the first invalid entry.
"""
function zip_test(r::ZipReader)::Nothing
for i in 1:zip_nentries(r)
try
zip_test_entry(r, i)
catch
error("entry $(i): $(repr(zip_name(r, i))) is invalid")
end
end
nothing
end

"""
zip_openentry(r::ZipReader, i::Union{AbstractString, Integer})
Expand Down
1 change: 1 addition & 0 deletions test/test_reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ end
)
r = ZipReader(testdata)
@test_throws ArgumentError zip_test_entry(r, 1)
@test_throws ErrorException zip_test(r)
end

@testset "Invalid Deflated data" begin
Expand Down
2 changes: 2 additions & 0 deletions test/test_simple-usage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ using Test: @testset, @test, @test_throws
# Test that an entry has a correct checksum.
zip_test_entry(r, 3)
zip_test_entry(r, 4)
# Test all the entries
zip_test(r)

# entries are not marked as executable by default
@test !zip_isexecutablefile(r, 1)
Expand Down

0 comments on commit 3dcffe9

Please sign in to comment.