Skip to content
Browse files

calculate fingerprints efficiently on large files using Digest::MD5.f…

…ile()

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
  • Loading branch information...
1 parent 2df79dd commit 290d914f07f116609c3233e7edb4c82b0baa5495 @cainlevy cainlevy committed with sikachu
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/paperclip/attachment.rb
View
10 lib/paperclip/attachment.rb
@@ -225,9 +225,13 @@ def hash(style_name = default_style)
end
def generate_fingerprint(source)
- data = source.read
- source.rewind if source.respond_to?(:rewind)
- Digest::MD5.hexdigest(data)
+ if source.respond_to?(:path) && source.path && !source.path.blank?
+ Digest::MD5.file(source.path).to_s
+ else
+ data = source.read
+ source.rewind if source.respond_to?(:rewind)
+ Digest::MD5.hexdigest(data)
+ end
end
# Paths and URLs can have a number of variables interpolated into them

0 comments on commit 290d914

Please sign in to comment.
Something went wrong with that request. Please try again.