From 5c57b8f430cc1752a365b0ecbf240c5cf2a3677e Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 20 Aug 2025 14:39:17 +0000 Subject: [PATCH 01/23] making crc32c as default --- .../lib/google/cloud/storage/bucket.rb | 1 + .../test/google/cloud/storage/bucket_test.rb | 45 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index ca8461354bb7..b55485149875 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1805,6 +1805,7 @@ def create_file file, path ||= file.path if file.respond_to? :path path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? + checksum = :crc32c if checksum == nil && crc32c.nil? && md5.nil? crc32c = crc32c_for file, checksum, crc32c md5 = md5_for file, checksum, md5 diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 203e423467e5..b32f6a23c0e0 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -101,6 +101,40 @@ _(bucket_complete.autoclass_enabled).must_equal bucket_autoclass_enabled _(bucket_complete.autoclass_terminal_storage_class).must_equal bucket_autoclass_terminal_storage_class end + + it "creates a file with checksum: :crc32c by default" do + new_file_name = random_file_path + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world!" + tmpfile.rewind + + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + + bucket.service.mocked_service = mock + bucket.create_file tmpfile, new_file_name + + mock.verify + end + end + + it "creates a file with a StringIO and checksum: :crc32c by default" do + new_file_name = random_file_path + new_file_contents = StringIO.new "Hello world" + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi(crc32c: "crUfeA==")], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + + bucket.service.mocked_service = mock + + bucket.create_file new_file_contents, new_file_name + + mock.verify + end it "returns frozen cors" do bucket_complete.cors.each do |cors| @@ -597,7 +631,7 @@ Tempfile.create ["google-cloud", ".txt"] do |tmpfile| mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket_user_project.name, new_file_name), - [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: "AAAAAA==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) bucket_user_project.service.mocked_service = mock @@ -610,7 +644,7 @@ it "creates an file with a StringIO" do new_file_name = random_file_path - new_file_contents = StringIO.new + new_file_contents = StringIO.new("Hello world") mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), @@ -1417,6 +1451,13 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, temporary_hold: nil, event_based_hold: nil + + # new_file_contents = StringIO.new + # Set crc32c if both md5 and crc32c are not provided + if md5.nil? && crc32c.nil? + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) + end + params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, From 7c7a46bb9f59435f40c8d211b16e3378f4528aa6 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 20 Aug 2025 14:53:12 +0000 Subject: [PATCH 02/23] refactoring --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index b55485149875..e0cd98b00300 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1805,7 +1805,7 @@ def create_file file, path ||= file.path if file.respond_to? :path path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? - checksum = :crc32c if checksum == nil && crc32c.nil? && md5.nil? + checksum = :crc32c if checksum.nil? && crc32c.nil? && md5.nil? crc32c = crc32c_for file, checksum, crc32c md5 = md5_for file, checksum, md5 From f0c499fb8e3b7421e844f1b3b8fdcab9f2086c3d Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 21 Aug 2025 09:06:32 +0000 Subject: [PATCH 03/23] modifying tests --- .../test/google/cloud/storage/bucket_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index b32f6a23c0e0..cf7861a4349a 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -127,7 +127,7 @@ new_file_contents = StringIO.new "Hello world" mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: "crUfeA==")], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) bucket.service.mocked_service = mock @@ -629,9 +629,11 @@ new_file_name = random_file_path Tempfile.create ["google-cloud", ".txt"] do |tmpfile| + + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket_user_project.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: "AAAAAA==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) bucket_user_project.service.mocked_service = mock From d6af83e058697c7a77d0325a4ac01b7313e57758 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 21 Aug 2025 09:11:45 +0000 Subject: [PATCH 04/23] removing commented line --- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index cf7861a4349a..b200f79aff0e 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1454,7 +1454,6 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, storage_class: nil, temporary_hold: nil, event_based_hold: nil - # new_file_contents = StringIO.new # Set crc32c if both md5 and crc32c are not provided if md5.nil? && crc32c.nil? crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) From 7563dfdee319a11f96315812217ea030cd649210 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 21 Aug 2025 11:23:21 +0000 Subject: [PATCH 05/23] modifying test cases --- .../lib/google/cloud/storage/file/verifier.rb | 2 ++ .../cloud/storage/bucket_encryption_test.rb | 4 +++ .../test/google/cloud/storage/bucket_test.rb | 8 +++--- .../google/cloud/storage/lazy/bucket_test.rb | 27 ++++++++++++++++++- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb index dcfefc6c616d..52bf667bf976 100644 --- a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb +++ b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb @@ -55,6 +55,7 @@ def self.md5_for local_file ::Digest::MD5.file(f).base64digest end else # StringIO + (local_file = ::File.open Pathname(local_file)) unless local_file.respond_to? :rewind local_file.rewind md5 = ::Digest::MD5.base64digest local_file.read local_file.rewind @@ -68,6 +69,7 @@ def self.crc32c_for local_file ::Digest::CRC32c.file(f).base64digest end else # StringIO + (local_file = ::File.open Pathname(local_file)) unless local_file.respond_to? :rewind local_file.rewind crc32c = ::Digest::CRC32c.base64digest local_file.read local_file.rewind diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index ce617da110e6..7fe89376cfd2 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -131,6 +131,10 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil + # Set crc32c if both md5 and crc32c are not provided + if md5.nil? && crc32c.nil? + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) + end params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index b200f79aff0e..7b9685f1dc08 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1454,10 +1454,10 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, storage_class: nil, temporary_hold: nil, event_based_hold: nil - # Set crc32c if both md5 and crc32c are not provided - if md5.nil? && crc32c.nil? - crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) - end + # Set crc32c if both md5 and crc32c are not provided + if md5.nil? && crc32c.nil? + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) + end params = { cache_control: cache_control, content_type: content_type, diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index c304f54b3838..f801118a5e54 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -244,6 +244,26 @@ mock.verify end end + + it "creates a file with checksum: :crc32c by default" do + new_file_name = random_file_path + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world!" + tmpfile.rewind + + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + + bucket.service.mocked_service = mock + bucket.create_file tmpfile, new_file_name + + mock.verify + end + end it "creates a file with attributes" do new_file_name = random_file_path @@ -340,9 +360,10 @@ new_file_name = random_file_path Tempfile.create ["google-cloud", ".txt"] do |tmpfile| + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket_user_project.name, new_file_name), - [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, user_project: "test", options: {retries: 0}) bucket_user_project.service.mocked_service = mock @@ -1091,6 +1112,10 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil + # Set crc32c if both md5 and crc32c are not provided + if md5.nil? && crc32c.nil? + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) + end params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, From ba3a630dfa591eb68c0d4e4203399be7b5b5b06c Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 21 Aug 2025 17:30:28 +0530 Subject: [PATCH 06/23] Update bucket_test.rb --- .../test/google/cloud/storage/lazy/bucket_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index f801118a5e54..5f530634f16b 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -253,7 +253,6 @@ tmpfile.rewind crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile - mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) From fb0ac510973814844fb3e5b4cd9d9145a479152e Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 16 Oct 2025 05:23:58 +0000 Subject: [PATCH 07/23] closing the intentionally opened file --- .../lib/google/cloud/storage/file/verifier.rb | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb index 52bf667bf976..c6d3626f7a77 100644 --- a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb +++ b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb @@ -48,32 +48,55 @@ def self.verify_md5 gcloud_file, local_file def self.verify_crc32c gcloud_file, local_file gcloud_file.crc32c == crc32c_for(local_file) end + # Calculates MD5 digest using either file path or open stream. + def self.md5_for(local_file) + _digest_for(local_file, ::Digest::MD5) + end - def self.md5_for local_file - if local_file.respond_to? :to_path - ::File.open Pathname(local_file).to_path, "rb" do |f| - ::Digest::MD5.file(f).base64digest - end - else # StringIO - (local_file = ::File.open Pathname(local_file)) unless local_file.respond_to? :rewind - local_file.rewind - md5 = ::Digest::MD5.base64digest local_file.read - local_file.rewind - md5 - end + # Calculates CRC32c digest using either file path or open stream. + def self.crc32c_for(local_file) + _digest_for(local_file, ::Digest::CRC32c) end - def self.crc32c_for local_file - if local_file.respond_to? :to_path + private + + # @private + # Computes a base64-encoded digest for a local file or IO stream. + # + # This method handles two types of inputs for `local_file`: + # 1. A file path (String or Pathname): It efficiently streams the file + # to compute the digest without loading the entire file into memory. + # 2. An IO-like stream (e.g., File, StringIO): It reads the stream's + # content to compute the digest. The stream is rewound before and after + # reading to ensure its position is not permanently changed. + # + # @param local_file [String, Pathname, IO] The local file path or IO + # stream for which to compute the digest. + # @param digest_class [Class] The digest class to use for the + # calculation (e.g., `Digest::MD5`). It must respond to `.file` and + # `.base64digest`. + # + # @return [String] The base64-encoded digest of the file's content. + # + def self._digest_for(local_file, digest_class) + if local_file.respond_to?(:to_path) + # Case 1: Input is a file path (or Pathname). Use the safe block form. ::File.open Pathname(local_file).to_path, "rb" do |f| - ::Digest::CRC32c.file(f).base64digest + digest_class.file(f).base64digest + end + else + # Case 2: Input is an open stream (like File or StringIO). + file_to_close = nil + file_to_close = local_file = ::File.open(Pathname(local_file).to_path, "rb") unless local_file.respond_to?(:rewind) + begin + local_file.rewind + digest = digest_class.base64digest local_file.read + local_file.rewind + digest + ensure + # Only close the stream if we explicitly opened it + file_to_close.close if file_to_close.respond_to?(:close) && !file_to_close.closed? end - else # StringIO - (local_file = ::File.open Pathname(local_file)) unless local_file.respond_to? :rewind - local_file.rewind - crc32c = ::Digest::CRC32c.base64digest local_file.read - local_file.rewind - crc32c end end end From ea292dd04b6589d5a11144540b643a91fc434532 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 16 Oct 2025 05:31:44 +0000 Subject: [PATCH 08/23] lintfix --- .../lib/google/cloud/storage/file/verifier.rb | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb index c6d3626f7a77..de807bd2dff8 100644 --- a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb +++ b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb @@ -48,18 +48,17 @@ def self.verify_md5 gcloud_file, local_file def self.verify_crc32c gcloud_file, local_file gcloud_file.crc32c == crc32c_for(local_file) end + # Calculates MD5 digest using either file path or open stream. - def self.md5_for(local_file) - _digest_for(local_file, ::Digest::MD5) + def self.md5_for local_file + _digest_for local_file, ::Digest::MD5 end # Calculates CRC32c digest using either file path or open stream. - def self.crc32c_for(local_file) - _digest_for(local_file, ::Digest::CRC32c) + def self.crc32c_for local_file + _digest_for local_file, ::Digest::CRC32c end - private - # @private # Computes a base64-encoded digest for a local file or IO stream. # @@ -78,8 +77,8 @@ def self.crc32c_for(local_file) # # @return [String] The base64-encoded digest of the file's content. # - def self._digest_for(local_file, digest_class) - if local_file.respond_to?(:to_path) + def self._digest_for local_file, digest_class + if local_file.respond_to? :to_path # Case 1: Input is a file path (or Pathname). Use the safe block form. ::File.open Pathname(local_file).to_path, "rb" do |f| digest_class.file(f).base64digest @@ -87,14 +86,17 @@ def self._digest_for(local_file, digest_class) else # Case 2: Input is an open stream (like File or StringIO). file_to_close = nil - file_to_close = local_file = ::File.open(Pathname(local_file).to_path, "rb") unless local_file.respond_to?(:rewind) + unless local_file.respond_to? :rewind + file_to_close = local_file = ::File.open Pathname(local_file).to_path, + "rb" + end begin local_file.rewind digest = digest_class.base64digest local_file.read local_file.rewind digest ensure - # Only close the stream if we explicitly opened it + # Only close the stream if we explicitly opened it file_to_close.close if file_to_close.respond_to?(:close) && !file_to_close.closed? end end From e8d120d522a47e4f8d2eb552abeed91f8c4abb0a Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 19 Nov 2025 04:46:16 +0000 Subject: [PATCH 09/23] refactor --- .../lib/google/cloud/storage/file/verifier.rb | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb index de807bd2dff8..c65f33bb7c08 100644 --- a/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb +++ b/google-cloud-storage/lib/google/cloud/storage/file/verifier.rb @@ -78,27 +78,18 @@ def self.crc32c_for local_file # @return [String] The base64-encoded digest of the file's content. # def self._digest_for local_file, digest_class - if local_file.respond_to? :to_path - # Case 1: Input is a file path (or Pathname). Use the safe block form. + + if local_file.respond_to?(:to_path) || local_file.is_a?(String) + # Case 1: Input is a file path (String, Pathname, or object that responds to :to_path). ::File.open Pathname(local_file).to_path, "rb" do |f| digest_class.file(f).base64digest end else - # Case 2: Input is an open stream (like File or StringIO). - file_to_close = nil - unless local_file.respond_to? :rewind - file_to_close = local_file = ::File.open Pathname(local_file).to_path, - "rb" - end - begin - local_file.rewind - digest = digest_class.base64digest local_file.read - local_file.rewind - digest - ensure - # Only close the stream if we explicitly opened it - file_to_close.close if file_to_close.respond_to?(:close) && !file_to_close.closed? - end + # Case 2: Input is an open stream (File or StringIO). + local_file.rewind + digest = digest_class.base64digest local_file.read + local_file.rewind + digest end end end From ce60e6df4354b0517e44abbe1c44ed81dbb8bd26 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 2 Jan 2026 13:21:43 +0000 Subject: [PATCH 10/23] fixing doc --- .../lib/google/cloud/storage/bucket.rb | 1 + .../google/cloud/storage/bucket_encryption_test.rb | 6 ++---- .../test/google/cloud/storage/bucket_test.rb | 12 +++++------- .../test/google/cloud/storage/lazy/bucket_test.rb | 7 +++---- google-cloud-storage/test/helper.rb | 8 ++++++++ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index e0cd98b00300..dcc14eecc55e 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1805,6 +1805,7 @@ def create_file file, path ||= file.path if file.respond_to? :path path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? + # setting crc32c as default checksum algorithm if none provided for integrity check checksum = :crc32c if checksum.nil? && crc32c.nil? && md5.nil? crc32c = crc32c_for file, checksum, crc32c md5 = md5_for file, checksum, md5 diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index 7fe89376cfd2..9ef437030531 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -131,10 +131,8 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil - # Set crc32c if both md5 and crc32c are not provided - if md5.nil? && crc32c.nil? - crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) - end + # Set crc32c if both md5 and crc32c are not provided + crc32c = set_crc32c_as_default(md5, crc32c) params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 7b9685f1dc08..f4db3bff8a0f 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -644,13 +644,13 @@ end end - it "creates an file with a StringIO" do + it "creates a file with StringIO" do new_file_name = random_file_path - new_file_contents = StringIO.new("Hello world") - + new_file_contents = StringIO.new("Hello world strngio") + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for new_file_contents mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) bucket.service.mocked_service = mock @@ -1455,9 +1455,7 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, event_based_hold: nil # Set crc32c if both md5 and crc32c are not provided - if md5.nil? && crc32c.nil? - crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) - end + crc32c = set_crc32c_as_default(md5, crc32c) params = { cache_control: cache_control, content_type: content_type, diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index 5f530634f16b..ccfc64876e70 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -249,7 +249,7 @@ new_file_name = random_file_path Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - tmpfile.write "Hello world!" + tmpfile.write "Hello world 123" tmpfile.rewind crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile @@ -1112,9 +1112,8 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil # Set crc32c if both md5 and crc32c are not provided - if md5.nil? && crc32c.nil? - crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) - end + crc32c = set_crc32c_as_default(md5, crc32c) + params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index 5d37f92feb26..f78cd5ab40cc 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -612,4 +612,12 @@ def restore_file_gapi bucket, file_name, generation=nil file_hash = random_file_hash(bucket, file_name, generation).to_json Google::Apis::StorageV1::Object.from_json file_hash end + + def set_crc32c_as_default md5, crc32c + # Set crc32c if both md5 and crc32c are not provided + if md5.nil? && crc32c.nil? + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) + end + crc32c + end end From 8b94669cd7b04dd3efebbd4442ead72d4e5234d5 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 7 Jan 2026 11:02:08 +0000 Subject: [PATCH 11/23] fix testcase --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 5 +---- .../test/google/cloud/storage/bucket_test.rb | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index dcc14eecc55e..69b3021f9ca4 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1640,10 +1640,7 @@ def file path, # * `crc32c` - Calculate and provide a checksum using the CRC32c hash. # * `all` - Calculate and provide checksums for all available verifications. # - # Optional. The default is `nil`. Do not provide if also providing a - # corresponding `crc32c` or `md5` argument. See - # [Validation](https://cloud.google.com/storage/docs/hashes-etags) - # for more information. + # Defaults to :crc32c if not provided. # @param [String] crc32c The CRC32c checksum of the file data, as # described in [RFC 4960, Appendix # B](http://tools.ietf.org/html/rfc4960#appendix-B). diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index f4db3bff8a0f..eacc954fa044 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -125,9 +125,10 @@ it "creates a file with a StringIO and checksum: :crc32c by default" do new_file_name = random_file_path new_file_contents = StringIO.new "Hello world" + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for new_file_contents mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) bucket.service.mocked_service = mock @@ -646,7 +647,7 @@ it "creates a file with StringIO" do new_file_name = random_file_path - new_file_contents = StringIO.new("Hello world strngio") + new_file_contents = StringIO.new("Hello world string_io") crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for new_file_contents mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), From 7077e2eb22aa2526d90de5e41f434838a5a2b34b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 7 Jan 2026 17:29:35 +0530 Subject: [PATCH 12/23] Remove unnecessary line in bucket_test.rb --- .../test/google/cloud/storage/lazy/bucket_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index ccfc64876e70..c0353aa684d3 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -298,7 +298,6 @@ Tempfile.open ["google-cloud", ".txt"] do |tmpfile| tmpfile.write "Hello world" tmpfile.rewind - metadata = { "player" => "Bob", score: 10 From 79f420d338b58b151b6cddadf386746acc7c3fff Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 27 Jan 2026 12:27:27 +0530 Subject: [PATCH 13/23] Update documentation for checksum defaults Clarify the default checksum behavior in documentation. --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 69b3021f9ca4..df2d197c2f9e 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1639,8 +1639,10 @@ def file path, # * `md5` - Calculate and provide a checksum using the MD5 hash. # * `crc32c` - Calculate and provide a checksum using the CRC32c hash. # * `all` - Calculate and provide checksums for all available verifications. + # Optional. The default is `crc32c`. Do not provide if also providing a + # corresponding `crc32c` or `md5` argument. See + # [Validation](https://cloud.google.com/storage/docs/hashes-etags) # - # Defaults to :crc32c if not provided. # @param [String] crc32c The CRC32c checksum of the file data, as # described in [RFC 4960, Appendix # B](http://tools.ietf.org/html/rfc4960#appendix-B). From c6558be85026af71ad8e8ba6a35a095a40cb739d Mon Sep 17 00:00:00 2001 From: Priti Chattopadhyay Date: Tue, 27 Jan 2026 14:18:11 +0530 Subject: [PATCH 14/23] Update documentation for checksum parameters --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index df2d197c2f9e..8dfa9f7e05df 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1642,6 +1642,7 @@ def file path, # Optional. The default is `crc32c`. Do not provide if also providing a # corresponding `crc32c` or `md5` argument. See # [Validation](https://cloud.google.com/storage/docs/hashes-etags) + # for more information. # # @param [String] crc32c The CRC32c checksum of the file data, as # described in [RFC 4960, Appendix From 090b64c2942b9eb8c173a31013f2bc6b2669432c Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 27 Jan 2026 19:48:57 +0000 Subject: [PATCH 15/23] adding disable checksum func --- .../lib/google/cloud/storage/bucket.rb | 4 +- .../cloud/storage/bucket_encryption_test.rb | 9 ++-- .../test/google/cloud/storage/bucket_test.rb | 46 ++++++++++++++++-- .../google/cloud/storage/lazy/bucket_test.rb | 47 +++++++++++++++++-- 4 files changed, 94 insertions(+), 12 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 8dfa9f7e05df..7954fc03d908 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1806,7 +1806,9 @@ def create_file file, path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? # setting crc32c as default checksum algorithm if none provided for integrity check - checksum = :crc32c if checksum.nil? && crc32c.nil? && md5.nil? + if checksum == true || [checksum, crc32c, md5].all?(&:nil?) + checksum = :crc32c + end crc32c = crc32c_for file, checksum, crc32c md5 = md5_for file, checksum, md5 diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index 9ef437030531..d77e2124db91 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -130,15 +130,18 @@ def create_file_gapi bucket=nil, name = nil def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, - storage_class: nil + storage_class: nil, checksum: nil + # Set crc32c if both md5 and crc32c are not provided - crc32c = set_crc32c_as_default(md5, crc32c) + if checksum != false + crc32c = set_crc32c_as_default(md5, crc32c) + end params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, - storage_class: storage_class }.delete_if { |_k, v| v.nil? } + storage_class: storage_class, checksum: checksum }.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index eacc954fa044..65536e1dd1fb 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -440,6 +440,43 @@ end end + it "creates a file with no checksum" do + new_file_name = random_file_path + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world!" + tmpfile.rewind + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi(checksum: false)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + + bucket.service.mocked_service = mock + + bucket.create_file tmpfile, new_file_name, checksum: false + mock.verify + end + end + + it "creates a file with crc32c if checksum is true" do + new_file_name = random_file_path + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world!" + tmpfile.rewind + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi(checksum: true, crc32c: "e5jnUQ==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + + bucket.service.mocked_service = mock + + bucket.create_file tmpfile, new_file_name, checksum: true + + mock.verify + end + end + it "creates a file with attributes" do new_file_name = random_file_path @@ -1453,18 +1490,19 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, temporary_hold: nil, - event_based_hold: nil + event_based_hold: nil, checksum: nil # Set crc32c if both md5 and crc32c are not provided - crc32c = set_crc32c_as_default(md5, crc32c) - + if checksum != false + crc32c = set_crc32c_as_default(md5, crc32c) + end params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, storage_class: storage_class, temporary_hold: temporary_hold, - event_based_hold: event_based_hold }.delete_if { |_k, v| v.nil? } + event_based_hold: event_based_hold, checksum: checksum }.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index c0353aa684d3..315b4d91d177 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -264,6 +264,43 @@ end end + it "creates a file with no checksum" do + new_file_name = random_file_path + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world!" + tmpfile.rewind + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi(checksum: false)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + + bucket.service.mocked_service = mock + + bucket.create_file tmpfile, new_file_name, checksum: false + mock.verify + end + end + + it "creates a file with crc32c if checksum is true" do + new_file_name = random_file_path + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world!" + tmpfile.rewind + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi(checksum: true, crc32c: "e5jnUQ==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + + bucket.service.mocked_service = mock + + bucket.create_file tmpfile, new_file_name, checksum: true + + mock.verify + end + end + it "creates a file with attributes" do new_file_name = random_file_path @@ -1109,16 +1146,18 @@ def create_file_gapi bucket=nil, name = nil def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, - storage_class: nil - # Set crc32c if both md5 and crc32c are not provided - crc32c = set_crc32c_as_default(md5, crc32c) + storage_class: nil, checksum: nil + # Set crc32c if both md5 and crc32c are not provided + if checksum != false + crc32c = set_crc32c_as_default(md5, crc32c) + end params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, - storage_class: storage_class }.delete_if { |_k, v| v.nil? } + storage_class: storage_class, checksum: checksum }.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end From 506d92d4d3c0411c1405f359ed8ac22e151b3a42 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 27 Jan 2026 20:09:26 +0000 Subject: [PATCH 16/23] undo doc --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 7954fc03d908..9fed1eab9752 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1643,7 +1643,6 @@ def file path, # corresponding `crc32c` or `md5` argument. See # [Validation](https://cloud.google.com/storage/docs/hashes-etags) # for more information. - # # @param [String] crc32c The CRC32c checksum of the file data, as # described in [RFC 4960, Appendix # B](http://tools.ietf.org/html/rfc4960#appendix-B). From e66fdb08cde9c2bacc6f3013c9f95927281f838b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 28 Jan 2026 08:34:59 +0000 Subject: [PATCH 17/23] fix test --- .../test/google/cloud/storage/bucket_encryption_test.rb | 2 +- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 2 +- .../test/google/cloud/storage/lazy/bucket_test.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index d77e2124db91..2d1b13fa7068 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -141,7 +141,7 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_disposition: content_disposition, md5_hash: md5, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, - storage_class: storage_class, checksum: checksum }.delete_if { |_k, v| v.nil? } + storage_class: storage_class}.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 65536e1dd1fb..8a424b9ab3bf 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1502,7 +1502,7 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, storage_class: storage_class, temporary_hold: temporary_hold, - event_based_hold: event_based_hold, checksum: checksum }.delete_if { |_k, v| v.nil? } + event_based_hold: event_based_hold }.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index 315b4d91d177..ec770de719db 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -1157,7 +1157,7 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_disposition: content_disposition, md5_hash: md5, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, - storage_class: storage_class, checksum: checksum }.delete_if { |_k, v| v.nil? } + storage_class: storage_class}.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end From 7212ef15ef0f6080e1d3f14f73bb7572e73306d2 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 2 Feb 2026 07:58:57 +0000 Subject: [PATCH 18/23] fixing condition --- .../lib/google/cloud/storage/bucket.rb | 2 +- .../cloud/storage/bucket_encryption_test.rb | 9 ++++---- .../test/google/cloud/storage/bucket_test.rb | 21 +++++++++---------- .../google/cloud/storage/lazy/bucket_test.rb | 8 +++---- google-cloud-storage/test/helper.rb | 6 +++--- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 9fed1eab9752..72e4c1a741b4 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1805,7 +1805,7 @@ def create_file file, path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? # setting crc32c as default checksum algorithm if none provided for integrity check - if checksum == true || [checksum, crc32c, md5].all?(&:nil?) + if [checksum, crc32c, md5].all?(&:nil?) || checksum == true checksum = :crc32c end crc32c = crc32c_for file, checksum, crc32c diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index 2d1b13fa7068..c5a68d2835b2 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -130,18 +130,17 @@ def create_file_gapi bucket=nil, name = nil def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, - storage_class: nil, checksum: nil + storage_class: nil, checksum: nil, content: nil # Set crc32c if both md5 and crc32c are not provided - if checksum != false - crc32c = set_crc32c_as_default(md5, crc32c) - end + crc32c ||= set_crc32c_as_default md5, crc32c, content, checksum + params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, - storage_class: storage_class}.delete_if { |_k, v| v.nil? } + storage_class: storage_class }.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 8a424b9ab3bf..5bee101961ad 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -106,14 +106,15 @@ new_file_name = random_file_path Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - tmpfile.write "Hello world!" + content = "Hello world!" + tmpfile.write content tmpfile.rewind crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c, content: content)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) bucket.service.mocked_service = mock bucket.create_file tmpfile, new_file_name @@ -128,7 +129,7 @@ crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for new_file_contents mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c, content: new_file_contents.read)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) bucket.service.mocked_service = mock @@ -290,7 +291,7 @@ mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: "crUfeA==")], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: "crUfeA==", content: new_file_contents.read)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) bucket.service.mocked_service = mock @@ -462,13 +463,13 @@ new_file_name = random_file_path Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - tmpfile.write "Hello world!" + content = "Hello world!" + tmpfile.write content tmpfile.rewind mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(checksum: true, crc32c: "e5jnUQ==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) - + [bucket.name, empty_file_gapi(content: content, checksum: true, crc32c: "e5jnUQ==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) bucket.service.mocked_service = mock bucket.create_file tmpfile, new_file_name, checksum: true @@ -1490,12 +1491,10 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, temporary_hold: nil, - event_based_hold: nil, checksum: nil + event_based_hold: nil, checksum: nil, content: nil # Set crc32c if both md5 and crc32c are not provided - if checksum != false - crc32c = set_crc32c_as_default(md5, crc32c) - end + crc32c ||= set_crc32c_as_default md5, crc32c, content, checksum params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index ec770de719db..4812e0ef757e 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -1146,18 +1146,16 @@ def create_file_gapi bucket=nil, name = nil def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, - storage_class: nil, checksum: nil + storage_class: nil, checksum: nil, content: nil # Set crc32c if both md5 and crc32c are not provided - if checksum != false - crc32c = set_crc32c_as_default(md5, crc32c) - end + crc32c ||= set_crc32c_as_default md5, crc32c, content, checksum params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, content_encoding: content_encoding, crc32c: crc32c, content_language: content_language, metadata: metadata, - storage_class: storage_class}.delete_if { |_k, v| v.nil? } + storage_class: storage_class }.delete_if { |_k, v| v.nil? } Google::Apis::StorageV1::Object.new(**params) end diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index f78cd5ab40cc..b98d2a7b355f 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -613,10 +613,10 @@ def restore_file_gapi bucket, file_name, generation=nil Google::Apis::StorageV1::Object.from_json file_hash end - def set_crc32c_as_default md5, crc32c + def set_crc32c_as_default md5, crc32c, content, checksum # Set crc32c if both md5 and crc32c are not provided - if md5.nil? && crc32c.nil? - crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) + if [checksum, crc32c, md5].all?(&:nil?) || checksum == true + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new(content || "Hello world")) end crc32c end From 45d861648f60518de141d5db1b933ba463f29f63 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 2 Feb 2026 08:09:44 +0000 Subject: [PATCH 19/23] fix --- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 5bee101961ad..d20f8d5927d4 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -129,7 +129,7 @@ crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for new_file_contents mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: crc32c, content: new_file_contents.read)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) bucket.service.mocked_service = mock @@ -291,7 +291,7 @@ mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: "crUfeA==", content: new_file_contents.read)], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: "crUfeA==")], **insert_object_args(name: new_file_name, upload_source: new_file_contents, options: {retries: 0}) bucket.service.mocked_service = mock From 2a4f36f67b3fa3360e6fd678332f9b2e5bd450eb Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 2 Feb 2026 10:51:18 +0000 Subject: [PATCH 20/23] fix --- .../lib/google/cloud/storage/bucket.rb | 2 ++ .../google/cloud/storage/bucket_encryption_test.rb | 4 ++-- .../test/google/cloud/storage/bucket_test.rb | 14 ++++++-------- .../test/google/cloud/storage/lazy/bucket_test.rb | 4 ++-- google-cloud-storage/test/helper.rb | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 72e4c1a741b4..bbcd243776f3 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1636,6 +1636,8 @@ def file path, # # Acceptable values are: # + # * true - Calculate and provide a checksum using the CRC32c hash. + # * false - Do not calculate or provide a checksum. # * `md5` - Calculate and provide a checksum using the MD5 hash. # * `crc32c` - Calculate and provide a checksum using the CRC32c hash. # * `all` - Calculate and provide checksums for all available verifications. diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index c5a68d2835b2..11bf845f5d18 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -130,10 +130,10 @@ def create_file_gapi bucket=nil, name = nil def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, - storage_class: nil, checksum: nil, content: nil + storage_class: nil, checksum: nil # Set crc32c if both md5 and crc32c are not provided - crc32c ||= set_crc32c_as_default md5, crc32c, content, checksum + crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { cache_control: cache_control, content_type: content_type, diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index d20f8d5927d4..d3ba234b0c94 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -106,15 +106,14 @@ new_file_name = random_file_path Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - content = "Hello world!" - tmpfile.write content + tmpfile.write "Hello world!" tmpfile.rewind crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for tmpfile mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(crc32c: crc32c, content: content)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + [bucket.name, empty_file_gapi(crc32c: crc32c)], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) bucket.service.mocked_service = mock bucket.create_file tmpfile, new_file_name @@ -463,13 +462,12 @@ new_file_name = random_file_path Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - content = "Hello world!" - tmpfile.write content + tmpfile.write "Hello world!" tmpfile.rewind mock = Minitest::Mock.new mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi(content: content, checksum: true, crc32c: "e5jnUQ==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) + [bucket.name, empty_file_gapi(checksum: true, crc32c: "e5jnUQ==")], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0}) bucket.service.mocked_service = mock bucket.create_file tmpfile, new_file_name, checksum: true @@ -1491,10 +1489,10 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, temporary_hold: nil, - event_based_hold: nil, checksum: nil, content: nil + event_based_hold: nil, checksum: nil # Set crc32c if both md5 and crc32c are not provided - crc32c ||= set_crc32c_as_default md5, crc32c, content, checksum + crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index 4812e0ef757e..3427e4e7aee8 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -1146,10 +1146,10 @@ def create_file_gapi bucket=nil, name = nil def empty_file_gapi cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, - storage_class: nil, checksum: nil, content: nil + storage_class: nil, checksum: nil # Set crc32c if both md5 and crc32c are not provided - crc32c ||= set_crc32c_as_default md5, crc32c, content, checksum + crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, md5_hash: md5, diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index b98d2a7b355f..3877488e55f2 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -613,10 +613,10 @@ def restore_file_gapi bucket, file_name, generation=nil Google::Apis::StorageV1::Object.from_json file_hash end - def set_crc32c_as_default md5, crc32c, content, checksum + def set_crc32c_as_default md5, crc32c, checksum # Set crc32c if both md5 and crc32c are not provided if [checksum, crc32c, md5].all?(&:nil?) || checksum == true - crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new(content || "Hello world")) + crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) end crc32c end From 8b803fc5389e34177fa7932b5775c6ee3b3b642a Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 2 Feb 2026 11:28:08 +0000 Subject: [PATCH 21/23] fix --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index bbcd243776f3..c6b098f72f8b 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1628,7 +1628,7 @@ def file path, # changed to a time in the future. If custom_time must be unset, you # must either perform a rewrite operation, or upload the data again # and create a new file. - # @param [Symbol, nil] checksum The type of checksum for the client to + # @param [Symbol, nil, Boolean] checksum The type of checksum for the client to # automatically calculate and send with the create request to verify # the integrity of the object. If provided, Cloud Storage will only # create the file if the value calculated by the client matches the @@ -1636,8 +1636,8 @@ def file path, # # Acceptable values are: # - # * true - Calculate and provide a checksum using the CRC32c hash. - # * false - Do not calculate or provide a checksum. + # * true [Boolean] - Calculate and provide a checksum using the CRC32c hash. + # * false [Boolean] - Do not calculate or provide a checksum. # * `md5` - Calculate and provide a checksum using the MD5 hash. # * `crc32c` - Calculate and provide a checksum using the CRC32c hash. # * `all` - Calculate and provide checksums for all available verifications. From 62387c15d13d6e7b50ef3b9c80652ff3e0f3be89 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 2 Feb 2026 11:49:46 +0000 Subject: [PATCH 22/23] fix doc --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 7 ++++--- .../test/google/cloud/storage/bucket_encryption_test.rb | 2 +- .../test/google/cloud/storage/bucket_test.rb | 2 +- .../test/google/cloud/storage/lazy/bucket_test.rb | 2 +- google-cloud-storage/test/helper.rb | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index c6b098f72f8b..fcda940d0804 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1636,8 +1636,8 @@ def file path, # # Acceptable values are: # - # * true [Boolean] - Calculate and provide a checksum using the CRC32c hash. - # * false [Boolean] - Do not calculate or provide a checksum. + # * `true` [Boolean] - Calculate and provide a checksum using the CRC32c hash. + # * `false` [Boolean] - Do not calculate or provide a checksum. # * `md5` - Calculate and provide a checksum using the MD5 hash. # * `crc32c` - Calculate and provide a checksum using the CRC32c hash. # * `all` - Calculate and provide checksums for all available verifications. @@ -1806,7 +1806,8 @@ def create_file file, path ||= file.path if file.respond_to? :path path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? - # setting crc32c as default checksum algorithm if none provided for integrity check + # if no checksum type is provided, and no specific checksum is provided, + # default to crc32c if [checksum, crc32c, md5].all?(&:nil?) || checksum == true checksum = :crc32c end diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index 11bf845f5d18..120bd6fb93cb 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -132,7 +132,7 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, checksum: nil - # Set crc32c if both md5 and crc32c are not provided + # Set crc32c if no checksum type is provided, and no specific checksum is provided crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index d3ba234b0c94..9923facb38ab 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1491,7 +1491,7 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, storage_class: nil, temporary_hold: nil, event_based_hold: nil, checksum: nil - # Set crc32c if both md5 and crc32c are not provided + # Set crc32c if no checksum type is provided, and no specific checksum is provided crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { cache_control: cache_control, content_type: content_type, diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index 3427e4e7aee8..db322274defe 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -1148,7 +1148,7 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, checksum: nil - # Set crc32c if both md5 and crc32c are not provided + # Set crc32c if no checksum type is provided, and no specific checksum is provided crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { cache_control: cache_control, content_type: content_type, diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index 3877488e55f2..44b74ba8ae45 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -614,7 +614,7 @@ def restore_file_gapi bucket, file_name, generation=nil end def set_crc32c_as_default md5, crc32c, checksum - # Set crc32c if both md5 and crc32c are not provided + # if no checksum type is provided, and no specific checksum is provided, default to crc32c if [checksum, crc32c, md5].all?(&:nil?) || checksum == true crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) end From 84496d9a6453a81aa1c39da917e43d46a882108e Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 2 Feb 2026 12:10:56 +0000 Subject: [PATCH 23/23] fix doc --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 4 ++-- .../test/google/cloud/storage/bucket_encryption_test.rb | 3 ++- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 3 ++- .../test/google/cloud/storage/lazy/bucket_test.rb | 3 ++- google-cloud-storage/test/helper.rb | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index fcda940d0804..6d71edf54e77 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1806,8 +1806,8 @@ def create_file file, path ||= file.path if file.respond_to? :path path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? - # if no checksum type is provided, and no specific checksum is provided, - # default to crc32c + # If no checksum type or specific value is provided, the default will be set to crc32c. + # If the checksum is set to false, it will be disabled. if [checksum, crc32c, md5].all?(&:nil?) || checksum == true checksum = :crc32c end diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb index 120bd6fb93cb..e7c10e8b5e04 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_encryption_test.rb @@ -132,7 +132,8 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, checksum: nil - # Set crc32c if no checksum type is provided, and no specific checksum is provided + # If no checksum type or specific value is provided, the default will be set to crc32c. + # If the checksum is set to false, it will be disabled. crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 9923facb38ab..340283319ff0 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1491,7 +1491,8 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, storage_class: nil, temporary_hold: nil, event_based_hold: nil, checksum: nil - # Set crc32c if no checksum type is provided, and no specific checksum is provided + # If no checksum type or specific value is provided, the default will be set to crc32c. + # If the checksum is set to false, it will be disabled. crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { cache_control: cache_control, content_type: content_type, diff --git a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb index db322274defe..ea8e93c7df94 100644 --- a/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/lazy/bucket_test.rb @@ -1148,7 +1148,8 @@ def empty_file_gapi cache_control: nil, content_disposition: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, checksum: nil - # Set crc32c if no checksum type is provided, and no specific checksum is provided + # If no checksum type or specific value is provided, the default will be set to crc32c. + # If the checksum is set to false, it will be disabled. crc32c ||= set_crc32c_as_default md5, crc32c, checksum params = { cache_control: cache_control, content_type: content_type, diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index 44b74ba8ae45..1f635b8b62bb 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -614,8 +614,8 @@ def restore_file_gapi bucket, file_name, generation=nil end def set_crc32c_as_default md5, crc32c, checksum - # if no checksum type is provided, and no specific checksum is provided, default to crc32c - if [checksum, crc32c, md5].all?(&:nil?) || checksum == true + # If no checksum type or specific value is provided, the default will be set to crc32c. + # If the checksum is set to false, it will be disabled. if [checksum, crc32c, md5].all?(&:nil?) || checksum == true crc32c = Google::Cloud::Storage::File::Verifier.crc32c_for(StringIO.new("Hello world")) end crc32c