diff options
| author | Aaron Patterson <tenderlove@ruby-lang.org> | 2025-09-12 16:29:51 +0900 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-09-16 17:17:32 +0900 |
| commit | a71b339477a291a93fc9f83266eaad3423df6acc (patch) | |
| tree | 68e133c3d15f61ceb7c7caffc05a055ac192bf28 | |
| parent | ca9c0f91311e01625e10272798ff2cc831bbee60 (diff) | |
[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
| -rw-r--r-- | lib/rubygems/package.rb | 12 |
1 files 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 |
