diff options
author | Tim Smith <tsmith84@gmail.com> | 2021-12-17 08:57:33 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2021-12-17 08:57:33 -0800 |
commit | 06c650886daa2a6eaf4c029cbf686ff401d44c48 (patch) | |
tree | 414a5bc2f8c7a5f07702a01c3fcb71b67026f189 /lib | |
parent | df9b3881518297274bebfac3c348d69f3de52197 (diff) | |
download | chef-06c650886daa2a6eaf4c029cbf686ff401d44c48.tar.gz |
Simplify file readssimplified_read
This is a new RuboCop cop that moves things to file.read an file.binread vs. an open and then a read.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
5 files changed, 5 insertions, 5 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb index c49ed51d81..35e412bd37 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb @@ -38,7 +38,7 @@ class Chef def read tmpfile = rest.streaming_request(file[:url]) - File.open(tmpfile, "rb", &:read) + File.binread(tmpfile) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading #{file[:url]}: #{e}") rescue Net::HTTPClientException => e diff --git a/lib/chef/chef_fs/file_system/repository/base_file.rb b/lib/chef/chef_fs/file_system/repository/base_file.rb index 94b52b9201..46c6494bb7 100644 --- a/lib/chef/chef_fs/file_system/repository/base_file.rb +++ b/lib/chef/chef_fs/file_system/repository/base_file.rb @@ -123,7 +123,7 @@ class Chef if is_ruby_file? data_handler.from_ruby(file_path).to_json else - File.open(file_path, "rb", &:read) + File.binread(file_path) end rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) diff --git a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb index 902bc63038..289ec26058 100644 --- a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb @@ -126,7 +126,7 @@ class Chef end def read - File.open(file_path, "rb", &:read) + File.binread(file_path) rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb index 21a15f706c..6b71b26d0c 100644 --- a/lib/chef/cookbook_uploader.rb +++ b/lib/chef/cookbook_uploader.rb @@ -119,7 +119,7 @@ class Chef # but we need the base64 encoding for the content-md5 # header checksum64 = Base64.encode64([checksum].pack("H*")).strip - file_contents = File.open(file, "rb", &:read) + file_contents = File.binread(file) # Custom headers. 'content-type' disables JSON serialization of the request body. headers = { "content-type" => "application/x-binary", "content-md5" => checksum64, "accept" => "application/json" } diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb index 8ca6249a9d..ae3c5c951d 100644 --- a/lib/chef/util/dsc/configuration_generator.rb +++ b/lib/chef/util/dsc/configuration_generator.rb @@ -175,7 +175,7 @@ class Chef::Util::DSC end def get_configuration_document(document_path) - ::File.open(document_path, "rb", &:read) + ::File.binread(document_path) end end end |