Skip to content

Commit 857002c

Browse files
committed
Use IO.copy_stream with IO object directly
Before this patch we would use `IO.copy_stream` with the tar entry object rather than just straight to the IO. That means every time copy_stream wanted data, we would have to proxy the call. The reason we did this is because every tar entry object _shares_ the same IO object, and previous to 8927533 we would call `IO.copy_stream` _without_ a size. Without passing a size, copy_stream will just read until there is nothing left to read, so these proxy object emulate finding "the end of the file" (where "end of file" means "end of tar chunk"). Without emulating this "end of file" behavior, copy_stream would just keep reading past the end of the tar chunk. However, now that we're passing the size to copy_stream, we can bypass the proxy object overhead and just use the IO object directly because copy_stream knows exactly the number of bytes it needs to read and will stop when it reaches the goal.
1 parent 21533ea commit 857002c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/rubygems/package.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
452452

453453
if entry.file?
454454
File.open(destination, "wb") do |out|
455-
copy_stream(entry, out, entry.size)
455+
copy_stream(tar.io, out, entry.size)
456456
# Flush needs to happen before chmod because there could be data
457457
# in the IO buffer that needs to be written, and that could be
458458
# written after the chmod (on close) which would mess up the perms

lib/rubygems/package/tar_reader.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def self.new(io)
3030
nil
3131
end
3232

33+
attr_reader :io # :nodoc:
34+
3335
##
3436
# Creates a new tar file reader on +io+ which needs to respond to #pos,
3537
# #eof?, #read, #getc and #pos=

0 commit comments

Comments
 (0)