CodecInflate64.jl is a work in progress Julia implementation of deflate64 decompression.
Deflate64 is an incompatible variant of deflate that Windows File Explorer sometimes uses when making large ZIP files.
If you have any large ZIP files created on Windows, please help me test this library by running the following script and reporting any errors here or on GitHub.
julia testzip.jl myzipfile.zip
# This script tests if CodecInflate64 can be used to correctly read a zip file.
# Run it with for example: `julia testzip.jl myzipfile.zip`
import Pkg
Pkg.activate(;temp=true)
Pkg.add([
"CodecInflate64",
"ZipArchives",
"CRC32",
"InputBuffers"
])
using ZipArchives, CRC32, InputBuffers, CodecInflate64, Mmap
function checkcrc32_zipfile(zipfile::String; bufsize=2^14)
data = mmap(open(zipfile; read=true))
r = ZipReader(data)
for i in 1:zip_nentries(r)
method = ZipArchives.zip_compression_method(r, i)
a = ZipArchives.zip_entry_data_offset(r,i)
s = zip_compressed_size(r,i)
c = data[begin+a:begin+a+s-1]
u = if method == 9
Deflate64DecompressorStream(InputBuffer(c); bufsize)
elseif method == 8
DeflateDecompressorStream(InputBuffer(c); bufsize)
elseif method == 0
InputBuffer(c)
else
error("unknown method in $(repr(zipfile)) entry: $(i) name: $(repr(zip_name(r,i)))")
end
if crc32(u) != zip_stored_crc32(r, i)
error("crc32 wrong for $(repr(zipfile)) entry: $(i) name: $(repr(zip_name(r,i)))")
end
end
@info "$(zip_nentries(r)) entries in $(repr(zipfile)) successfully checked"
end
checkcrc32_zipfile(ARGS[1])
Spaces in filenames are fine, just put them in quotes when running the script: julia testzip.jl "my zip file with spaces.zip"
Alternatively, you can run the checkcrc32_zipfile function directly in the REPL to avoid CLI issues:
using ZipArchives, CRC32, InputBuffers, CodecInflate64, Mmap
function checkcrc32_zipfile(zipfile::String; bufsize=2^14)
data = mmap(open(zipfile; read=true))
r = ZipReader(data)
for i in 1:zip_nentries(r)
method = ZipArchives.zip_compression_method(r, i)
a = ZipArchives.zip_entry_data_offset(r,i)
s = zip_compressed_size(r,i)
c = data[begin+a:begin+a+s-1]
u = if method == 9
Deflate64DecompressorStream(InputBuffer(c); bufsize)
elseif method == 8
DeflateDecompressorStream(InputBuffer(c); bufsize)
elseif method == 0
InputBuffer(c)
else
error("unknown method: $(method) in $(repr(zipfile)) entry: $(i) name: $(repr(zip_name(r,i)))")
end
if crc32(u) != zip_stored_crc32(r, i)
error("crc32 wrong for $(repr(zipfile)) entry: $(i) name: $(repr(zip_name(r,i)))")
end
end
@info "$(zip_nentries(r)) entries in $(repr(zipfile)) successfully checked"
end
checkcrc32_zipfile("my zip file with spaces")