From a71b339477a291a93fc9f83266eaad3423df6acc Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 12 Sep 2025 16:29:51 +0900 Subject: [rubygems/rubygems] Pass the file size to IO.copy_stream When extracting tar files, the tar header actually knows the exact size of the file we need to extract. Before this commit, we would read the file from the tar file until it returned `nil`. We can be a little more efficient when copying by passing the size to copy_stream https://github.com/rubygems/rubygems/commit/8927533b0a --- lib/rubygems/package.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 99be691ec7..0873040206 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -267,7 +267,7 @@ class Gem::Package tar.add_file_simple file, stat.mode, stat.size do |dst_io| File.open file, "rb" do |src_io| - copy_stream(src_io, dst_io) + copy_stream(src_io, dst_io, stat.size) end end end @@ -452,7 +452,7 @@ EOM if entry.file? File.open(destination, "wb") do |out| - copy_stream(entry, out) + copy_stream(entry, out, entry.size) # Flush needs to happen before chmod because there could be data # in the IO buffer that needs to be written, and that could be # written after the chmod (on close) which would mess up the perms @@ -721,12 +721,12 @@ EOM end if RUBY_ENGINE == "truffleruby" - def copy_stream(src, dst) # :nodoc: - dst.write src.read + def copy_stream(src, dst, size) # :nodoc: + dst.write src.read(size) end else - def copy_stream(src, dst) # :nodoc: - IO.copy_stream(src, dst) + def copy_stream(src, dst, size) # :nodoc: + IO.copy_stream(src, dst, size) end end -- cgit v1.2.3