Skip to content

Commit 79bcc3f

Browse files
committed
Much smarter file wrapper that loads in files one chunk at a time
1 parent aba4a66 commit 79bcc3f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/SHA.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ for (f, ctx) in [(:sha1, :SHA1_CTX),
4949
# open("test.txt") do f
5050
# sha256(f)
5151
# done
52-
$f(io::IO) = $f(read(io))
52+
function $f(io::IO, chunk_size=4*1024)
53+
ctx = $ctx()
54+
buff = Vector{UInt8}(chunk_size)
55+
while !eof(io)
56+
num_read = readbytes!(io, buff)
57+
update!(ctx, buff[1:num_read])
58+
end
59+
return digest!(ctx)
60+
end
5361
end
5462
end
5563

0 commit comments

Comments
 (0)