Skip to content

Commit 558f516

Browse files
authored
Merge pull request #6958 from rubygems/martinemde/io-copy-stream
Use IO.copy_stream when reading, writing
2 parents 6c36dc4 + cea0fbb commit 558f516

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/rubygems/package.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def add_files(tar) # :nodoc:
268268

269269
tar.add_file_simple file, stat.mode, stat.size do |dst_io|
270270
File.open file, "rb" do |src_io|
271-
dst_io.write src_io.read 16_384 until src_io.eof?
271+
copy_stream(src_io, dst_io)
272272
end
273273
end
274274
end
@@ -453,7 +453,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
453453
end
454454

455455
if entry.file?
456-
File.open(destination, "wb") {|out| out.write entry.read }
456+
File.open(destination, "wb") {|out| copy_stream(entry, out) }
457457
FileUtils.chmod file_mode(entry.header.mode), destination
458458
end
459459

@@ -714,6 +714,16 @@ def verify_gz(entry) # :nodoc:
714714
rescue Zlib::GzipFile::Error => e
715715
raise Gem::Package::FormatError.new(e.message, entry.full_name)
716716
end
717+
718+
if RUBY_ENGINE == "truffleruby"
719+
def copy_stream(src, dst) # :nodoc:
720+
dst.write src.read
721+
end
722+
else
723+
def copy_stream(src, dst) # :nodoc:
724+
IO.copy_stream(src, dst)
725+
end
726+
end
717727
end
718728

719729
require_relative "package/digest_io"

0 commit comments

Comments
 (0)