File tree Expand file tree Collapse file tree 1 file changed +8
-17
lines changed
google-cloud-storage/lib/google/cloud/storage/file Expand file tree Collapse file tree 1 file changed +8
-17
lines changed Original file line number Diff line number Diff line change @@ -78,27 +78,18 @@ def self.crc32c_for local_file
7878 # @return [String] The base64-encoded digest of the file's content.
7979 #
8080 def self . _digest_for local_file , digest_class
81- if local_file . respond_to? :to_path
82- # Case 1: Input is a file path (or Pathname). Use the safe block form.
81+
82+ if local_file . respond_to? ( :to_path ) || local_file . is_a? ( String )
83+ # Case 1: Input is a file path (String, Pathname, or object that responds to :to_path).
8384 ::File . open Pathname ( local_file ) . to_path , "rb" do |f |
8485 digest_class . file ( f ) . base64digest
8586 end
8687 else
87- # Case 2: Input is an open stream (like File or StringIO).
88- file_to_close = nil
89- unless local_file . respond_to? :rewind
90- file_to_close = local_file = ::File . open Pathname ( local_file ) . to_path ,
91- "rb"
92- end
93- begin
94- local_file . rewind
95- digest = digest_class . base64digest local_file . read
96- local_file . rewind
97- digest
98- ensure
99- # Only close the stream if we explicitly opened it
100- file_to_close . close if file_to_close . respond_to? ( :close ) && !file_to_close . closed?
101- end
88+ # Case 2: Input is an open stream (File or StringIO).
89+ local_file . rewind
90+ digest = digest_class . base64digest local_file . read
91+ local_file . rewind
92+ digest
10293 end
10394 end
10495 end
You can’t perform that action at this time.
0 commit comments