From 79bcc3fd79c1a6cc8678c39b74d721097c5cb2b0 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Wed, 1 Nov 2017 03:15:47 -0700 Subject: [PATCH] Much smarter file wrapper that loads in files one chunk at a time --- src/SHA.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SHA.jl b/src/SHA.jl index b8d328e..2dc48c2 100644 --- a/src/SHA.jl +++ b/src/SHA.jl @@ -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