Skip to content

Commit 5b62994

Browse files
Merge pull request rails#50418 from the-spectator/buffered_checksum
Use buffered read while generating Blob checksum to improve memory
2 parents 16ff9af + 92138c4 commit 5b62994

File tree

1 file changed

+3
-2
lines changed
  • activestorage/app/models/active_storage

1 file changed

+3
-2
lines changed

activestorage/app/models/active_storage/blob.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ def compute_checksum_in_chunks(io)
350350
raise ArgumentError, "io must be rewindable" unless io.respond_to?(:rewind)
351351

352352
OpenSSL::Digest::MD5.new.tap do |checksum|
353-
while chunk = io.read(5.megabytes)
354-
checksum << chunk
353+
read_buffer = "".b
354+
while io.read(5.megabytes, read_buffer)
355+
checksum << read_buffer
355356
end
356357

357358
io.rewind

0 commit comments

Comments
 (0)