TarOutput is a wrapper to TarWriter that builds gem-format tar file.
Gem-format tar files contain the following files:
A gzipped tar file containing the files that compose the gem which will be extracted into the gem/ dir on installation.
A YAML format Gem::Specification.
A signature for the gem’s data.tar.gz.
A signature for the gem’s metadata.gz.
See TarOutput::open for usage details.
Creates a new TarOutput that will write a gem-format tar file to io. If signer is given, the data.tar.gz and metadata.gz will be signed and the signatures will be added to the tar file.
# File lib/rubygems/package/tar_output.rb, line 44 44: def initialize(io, signer) 45: @io = io 46: @signer = signer 47: 48: @tar_writer = Gem::Package::TarWriter.new @io 49: 50: @metadata = nil 51: 52: @data_signature = nil 53: @meta_signature = nil 54: end
Creates a new TarOutput which will yield a TarWriter object for the data.tar.gz portion of a gem-format tar file.
See # for details on io and signer.
See # for details on adding metadata to the tar file.
# File lib/rubygems/package/tar_output.rb, line 29 29: def self.open(io, signer = nil, &block) # :yield: data_tar_writer 30: tar_outputter = new io, signer 31: tar_outputter.add_gem_contents(&block) 32: tar_outputter.add_metadata 33: tar_outputter.add_signatures 34: 35: ensure 36: tar_outputter.close 37: end
Yields a TarWriter for the data.tar.gz inside a gem-format tar file. The yielded TarWriter has been extended with a # method for attaching a YAML format Gem::Specification which will be written by add_metadata.
# File lib/rubygems/package/tar_output.rb, line 62 62: def add_gem_contents 63: @tar_writer.add_file "data.tar.gz", 0644 do |inner| 64: sio = @signer ? StringIO.new : nil 65: Zlib::GzipWriter.wrap(sio || inner) do |os| 66: 67: Gem::Package::TarWriter.new os do |data_tar_writer| 68: # :stopdoc: 69: def data_tar_writer.metadata() @metadata end 70: def data_tar_writer.metadata=(metadata) @metadata = metadata end 71: # :startdoc: 72: 73: yield data_tar_writer 74: 75: @metadata = data_tar_writer.metadata 76: end 77: end 78: 79: # if we have a signing key, then sign the data 80: # digest and return the signature 81: if @signer then 82: digest = Gem::Security::OPT[:dgst_algo].digest sio.string 83: @data_signature = @signer.sign digest 84: inner.write sio.string 85: end 86: end 87: 88: self 89: end
Adds metadata.gz to the gem-format tar file which was saved from a previous # call.
# File lib/rubygems/package/tar_output.rb, line 95 95: def add_metadata 96: return if @metadata.nil? 97: 98: @tar_writer.add_file "metadata.gz", 0644 do |io| 99: begin 100: sio = @signer ? StringIO.new : nil 101: gzos = Zlib::GzipWriter.new(sio || io) 102: gzos.write @metadata 103: ensure 104: gzos.flush 105: gzos.finish 106: 107: # if we have a signing key, then sign the metadata digest and return 108: # the signature 109: if @signer then 110: digest = Gem::Security::OPT[:dgst_algo].digest sio.string 111: @meta_signature = @signer.sign digest 112: io.write sio.string 113: end 114: end 115: end 116: end
Adds data.tar.gz.sig and metadata.gz.sig to the gem-format tar files if a Gem::Security::Signer was sent to initialize.
# File lib/rubygems/package/tar_output.rb, line 122 122: def add_signatures 123: if @data_signature then 124: @tar_writer.add_file 'data.tar.gz.sig', 0644 do |io| 125: io.write @data_signature 126: end 127: end 128: 129: if @meta_signature then 130: @tar_writer.add_file 'metadata.gz.sig', 0644 do |io| 131: io.write @meta_signature 132: end 133: end 134: end
Closes the TarOutput.
# File lib/rubygems/package/tar_output.rb, line 139 139: def close 140: @tar_writer.close 141: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.