Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up and export crc32c function #22274

Merged
merged 14 commits into from
Jun 13, 2017
Prev Previous commit
Next Next commit
crc32c(IOBuffer) bugfix and test
  • Loading branch information
stevengj committed Jun 8, 2017
commit f34d08c19fd31605b3b6008530d75d2081cfe869
2 changes: 1 addition & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ unsafe_crc32c(a, n, crc) = ccall(:jl_crc32c, UInt32, (UInt32, Ptr{UInt8}, Csize_
crc32c(a::Union{Array{UInt8},FastContiguousSubArray{UInt8,N,<:Array{UInt8}} where N}, crc::UInt32=0x00000000) =
unsafe_crc32c(a, length(a), crc)

crc32c(buf::IOBuffer, crc::UInt32=0x00000000) = crc32c(buf.data, crc)
crc32c(buf::IOBuffer, crc::UInt32=0x00000000) = unsafe_crc32c(buf.data, min(buf.size, length(buf.data)), crc)

"""
crc32c(f::IO, nb::Integer, crc::UInt32=0x00000000)
Expand Down
5 changes: 5 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ for force_software_crc in (1,0)
end

@test crc32c(IOBuffer(a)) == crc_256
let buf = IOBuffer()
write(buf, a[1:3])
@test crc32c(buf) == crc32c(a[1:3])
end

let f = tempname()
try
write(f, a)
Expand Down