-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduced memory usage when computing checksums of files.
Fixes #1098
- Loading branch information
1 parent
7cbfbef
commit d848206
Showing
8 changed files
with
93 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'openssl' | ||
require 'tempfile' | ||
|
||
module Aws | ||
# @api private | ||
module Checksums | ||
class << self | ||
|
||
# @param [File, Tempfile, IO#read, String] value | ||
# @return [String<SHA256 Hexdigest>] | ||
def sha256_hexdigest(value) | ||
if File === value || Tempfile === value | ||
OpenSSL::Digest::SHA256.file(value).hexdigest | ||
elsif value.respond_to?(:read) | ||
OpenSSL::Digest::SHA256.hexdigest(read_and_rewind(value)) | ||
else | ||
OpenSSL::Digest::SHA256.hexdigest(value) | ||
end | ||
end | ||
|
||
# @param [File, Tempfile, IO#read, String] value | ||
# @return [String<MD5>] | ||
def md5(value) | ||
if File === value || Tempfile === value | ||
Base64.encode64(OpenSSL::Digest::MD5.file(value).digest).strip | ||
elsif value.respond_to?(:read) | ||
Base64.encode64(OpenSSL::Digest::MD5.digest(read_and_rewind(value))).strip | ||
else | ||
Base64.encode64(OpenSSL::Digest::MD5.digest(value)).strip | ||
end | ||
end | ||
|
||
private | ||
|
||
def read_and_rewind(io) | ||
value = io.read | ||
io.rewind | ||
value | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters