@@ -5,19 +5,27 @@ function unsafe_crc32(p::Ptr{UInt8}, nb::UInt, crc::UInt32)::UInt32
55 )
66end
77
8- const ByteArray = Union{
9- Base. CodeUnits{UInt8, String},
10- Vector{UInt8},
11- Base. FastContiguousSubArray{UInt8,1 ,Base. CodeUnits{UInt8,String}},
12- Base. FastContiguousSubArray{UInt8,1 ,Vector{UInt8}}
13- }
8+ if VERSION ≥ v " 1.11"
9+ const ByteArray = Union{
10+ Base. CodeUnits{UInt8, String},
11+ Vector{UInt8},
12+ Base. FastContiguousSubArray{UInt8,1 ,Base. CodeUnits{UInt8,String}},
13+ Base. FastContiguousSubArray{UInt8,1 ,Vector{UInt8}},
14+ Memory{UInt8},
15+ Base. FastContiguousSubArray{UInt8,1 ,Memory{UInt8}}
16+ }
17+ else
18+ const ByteArray = Union{
19+ Base. CodeUnits{UInt8, String},
20+ Vector{UInt8},
21+ Base. FastContiguousSubArray{UInt8,1 ,Base. CodeUnits{UInt8,String}},
22+ Base. FastContiguousSubArray{UInt8,1 ,Vector{UInt8}}
23+ }
24+ end
1425
1526# version of String(v::AbstractVector{UInt8}) that works consistently.
1627function bytes2string (v:: AbstractVector{UInt8} ):: String
17- String (v)
18- end
19- function bytes2string (v:: Vector{UInt8} ):: String
20- GC. @preserve v unsafe_string (pointer (v), length (v))
28+ String (view (v,:))
2129end
2230
2331"""
@@ -32,7 +40,17 @@ function zip_crc32(data::ByteArray, crc::UInt32=UInt32(0))::UInt32
3240end
3341
3442function zip_crc32 (data:: AbstractVector{UInt8} , crc:: UInt32 = UInt32 (0 )):: UInt32
35- zip_crc32 (collect (data), crc)
43+ start:: Int64 = firstindex (data)
44+ n:: Int64 = length (data)
45+ offset:: Int64 = 0
46+ buf = Vector {UInt8} (undef, min (n, Int64 (24576 )))
47+ while offset < n
48+ nb = min (n- offset, Int64 (24576 ))
49+ copyto! (buf, 1 , data, offset + start, nb)
50+ crc = zip_crc32 (view (buf, 1 : nb), crc)
51+ offset += nb
52+ end
53+ crc
3654end
3755
3856@inline readle (io:: IO , :: Type{UInt64} ) = UInt64 (readle (io, UInt32)) | UInt64 (readle (io, UInt32))<< 32
0 commit comments