class YARD::CLI::Diff

def expand_gem(gemfile, io)

def expand_gem(gemfile, io)
  tmpdir = File.join(Dir.tmpdir, gemfile)
  FileUtils.mkdir_p(tmpdir)
  log.info "Expanding #{gemfile} to #{tmpdir}..."
  if Gem::VERSION >= '2.0.0'
    require 'rubygems/package/tar_reader'
    reader = Gem::Package::TarReader.new(io)
    reader.each do |pkg|
      next unless pkg.full_name == 'data.tar.gz'
      Zlib::GzipReader.wrap(pkg) do |gzio|
        tar = Gem::Package::TarReader.new(gzio)
        tar.each do |entry|
          file = File.join(tmpdir, entry.full_name)
          FileUtils.mkdir_p(File.dirname(file))
          File.open(file, 'wb') do |out|
            out.write(entry.read)
            begin
              out.fsync
            rescue NotImplementedError
              nil # noop
            end
          end
        end
      end
      break
    end
  else
    Gem::Package.open(io) do |pkg|
      pkg.each do |entry|
        pkg.extract_entry(tmpdir, entry)
      end
    end
  end
  tmpdir
end