Commit 290d914f by Lance Ivy Committed by Prem Sichanugrist

calculate fingerprints efficiently on large files using Digest::MD5.file()

The tests would broken for StringIO, because it doesn't have a real "path". I've modify the patch to make the test stop complaining [@sikachu]

This closes #470
parent 2df79dd3
...@@ -225,10 +225,14 @@ module Paperclip ...@@ -225,10 +225,14 @@ module Paperclip
end end
def generate_fingerprint(source) def generate_fingerprint(source)
if source.respond_to?(:path) && source.path && !source.path.blank?
Digest::MD5.file(source.path).to_s
else
data = source.read data = source.read
source.rewind if source.respond_to?(:rewind) source.rewind if source.respond_to?(:rewind)
Digest::MD5.hexdigest(data) Digest::MD5.hexdigest(data)
end end
end
# Paths and URLs can have a number of variables interpolated into them # Paths and URLs can have a number of variables interpolated into them
# to vary the storage location based on name, id, style, class, etc. # to vary the storage location based on name, id, style, class, etc.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment