Class Gem::Package::TarOutput
In: lib/rubygems/package/tar_output.rb
Parent: Object

TarOutput is a wrapper to TarWriter that builds gem-format tar file.

Gem-format tar files contain the following files:

data.tar.gz
A gzipped tar file containing the files that compose the gem which will be extracted into the gem/ dir on installation.
metadata.gz
A YAML format Gem::Specification.
data.tar.gz.sig
A signature for the gem‘s data.tar.gz.
metadata.gz.sig
A signature for the gem‘s metadata.gz.

See TarOutput::open for usage details.

Methods

Public Class methods

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.

[Source]

    # File lib/rubygems/package/tar_output.rb, line 43
43:   def initialize(io, signer)
44:     @io = io
45:     @signer = signer
46: 
47:     @tar_writer = Gem::Package::TarWriter.new @io
48: 
49:     @metadata = nil
50: 
51:     @data_signature = nil
52:     @meta_signature = nil
53:   end

Creates a new TarOutput which will yield a TarWriter object for the data.tar.gz portion of a gem-format tar file.

See initialize for details on io and signer.

See add_gem_contents for details on adding metadata to the tar file.

[Source]

    # File lib/rubygems/package/tar_output.rb, line 28
28:   def self.open(io, signer = nil, &block) # :yield: data_tar_writer
29:     tar_outputter = new io, signer
30:     tar_outputter.add_gem_contents(&block)
31:     tar_outputter.add_metadata
32:     tar_outputter.add_signatures
33: 
34:   ensure
35:     tar_outputter.close
36:   end

Public Instance methods

Yields a TarWriter for the data.tar.gz inside a gem-format tar file. The yielded TarWriter has been extended with a metadata= method for attaching a YAML format Gem::Specification which will be written by add_metadata.

[Source]

    # File lib/rubygems/package/tar_output.rb, line 61
61:   def add_gem_contents
62:     @tar_writer.add_file "data.tar.gz", 0644 do |inner|
63:       sio = @signer ? StringIO.new : nil
64:       Zlib::GzipWriter.wrap(sio || inner) do |os|
65: 
66:         Gem::Package::TarWriter.new os do |data_tar_writer|
67:           # :stopdoc:
68:           def data_tar_writer.metadata() @metadata end
69:           def data_tar_writer.metadata=(metadata) @metadata = metadata end
70:           # :startdoc:
71: 
72:           yield data_tar_writer
73: 
74:           @metadata = data_tar_writer.metadata
75:         end
76:       end
77: 
78:       # if we have a signing key, then sign the data
79:       # digest and return the signature
80:       if @signer then
81:         digest = Gem::Security::OPT[:dgst_algo].digest sio.string
82:         @data_signature = @signer.sign digest
83:         inner.write sio.string
84:       end
85:     end
86: 
87:     self
88:   end

Adds metadata.gz to the gem-format tar file which was saved from a previous add_gem_contents call.

[Source]

     # File lib/rubygems/package/tar_output.rb, line 94
 94:   def add_metadata
 95:     return if @metadata.nil?
 96: 
 97:     @tar_writer.add_file "metadata.gz", 0644 do |io|
 98:       begin
 99:         sio = @signer ? StringIO.new : nil
100:         gzos = Zlib::GzipWriter.new(sio || io)
101:         gzos.write @metadata
102:       ensure
103:         gzos.flush
104:         gzos.finish
105: 
106:         # if we have a signing key, then sign the metadata digest and return
107:         # the signature
108:         if @signer then
109:           digest = Gem::Security::OPT[:dgst_algo].digest sio.string
110:           @meta_signature = @signer.sign digest
111:           io.write sio.string
112:         end
113:       end
114:     end
115:   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.

[Source]

     # File lib/rubygems/package/tar_output.rb, line 121
121:   def add_signatures
122:     if @data_signature then
123:       @tar_writer.add_file 'data.tar.gz.sig', 0644 do |io|
124:         io.write @data_signature
125:       end
126:     end
127: 
128:     if @meta_signature then
129:       @tar_writer.add_file 'metadata.gz.sig', 0644 do |io|
130:         io.write @meta_signature
131:       end
132:     end
133:   end

Closes the TarOutput.

[Source]

     # File lib/rubygems/package/tar_output.rb, line 138
138:   def close
139:     @tar_writer.close
140:   end

[Validate]