Skip to content

Commit

Permalink
Much smarter file wrapper that loads in files one chunk at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Nov 1, 2017
1 parent aba4a66 commit 79bcc3f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/SHA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ for (f, ctx) in [(:sha1, :SHA1_CTX),
# open("test.txt") do f
# sha256(f)
# done
$f(io::IO) = $f(read(io))
function $f(io::IO, chunk_size=4*1024)
ctx = $ctx()
buff = Vector{UInt8}(chunk_size)
while !eof(io)
num_read = readbytes!(io, buff)
update!(ctx, buff[1:num_read])
end
return digest!(ctx)
end
end
end

Expand Down

0 comments on commit 79bcc3f

Please sign in to comment.