Module: RactorRailsShim::ActiveStorageAttachedPatch::BlobChecksumPatch

Defined in:
lib/ractor_rails_shim/patches/active_storage.rb

Overview

ActiveStorage::Blob#compute_checksum_in_chunks computes the MD5 via OpenSSL::Digest::MD5.new.tap do |checksum| ... endtap takes a block compiled in the main Ractor, which is un-shareable and raises "defined with an un-shareable Proc in a different Ractor" when a worker uploads an attachment. Reimplement without a block (plain while loop).

Instance Method Summary collapse

Instance Method Details

#compute_checksum_in_chunks(io) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ractor_rails_shim/patches/active_storage.rb', line 47

def compute_checksum_in_chunks(io)
  raise ArgumentError, "io must be rewindable" unless io.respond_to?(:rewind)

  checksum = OpenSSL::Digest::MD5.new
  read_buffer = "".b
  while io.read(5.megabytes, read_buffer)
    checksum << read_buffer
  end
  io.rewind
  checksum.base64digest
end