Skip to content

Commit 759dbf1

Browse files
authored
Merge pull request #91 from thedacheng/large-zip-file
Read zip file with size larger than 2^31
2 parents 4fa9be5 + 7c4b7e8 commit 759dbf1

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/ZipFile.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,15 @@ end
513513
"advance io position state and crc32 checksum, checking it at eof"
514514
function update_reader!(f::ReadableFile, data::Array{UInt8})
515515
f._zpos = position(f._io) - f._datapos
516-
f._pos += length(data)
517-
f._currentcrc32 = Zlib.crc32(data, f._currentcrc32)
516+
datalen = length(data)
517+
f._pos += datalen
518+
chunk_size = if Sys.WORD_SIZE > 32 2^31 else datalen end
519+
start = 1
520+
while datalen > 0
521+
f._currentcrc32 = Zlib.crc32(view(data, start:start-1+min(datalen, chunk_size)), f._currentcrc32)
522+
datalen -= chunk_size
523+
start += chunk_size
524+
end
518525

519526
if eof(f)
520527
if f.method == Deflate

src/Zlib.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ function eof(r::Reader)
365365
bytesavailable(r.buf) == 0 && eof(r.io)
366366
end
367367

368-
function crc32(data::Vector{UInt8}, crc::Integer=0)
368+
function crc32(data::AbstractArray{UInt8}, crc::Integer=0)
369369
convert(UInt32, (ccall((:crc32, libz),
370370
Culong, (Culong, Ptr{UInt8}, Cuint),
371371
crc, data, length(data))))
372372
end
373373

374-
crc32(data::AbstractString, crc::Integer=0) = crc32(convert(Vector{UInt8}, data), crc)
374+
crc32(data::AbstractString, crc::Integer=0) = crc32(convert(AbstractArray{UInt8}, data), crc)
375375

376376
end # module

0 commit comments

Comments
 (0)