Parent

Class Index [+]

Quicksearch

Gem::Package::TarOutput

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.

Public Class Methods

new(io, signer) click to toggle source

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
open(io, signer = nil) click to toggle source

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

Public Instance Methods

add_gem_contents() click to toggle source

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:         require 'rubygems/security'
83:         digest = Gem::Security::OPT[:dgst_algo].digest sio.string
84:         @data_signature = @signer.sign digest
85:         inner.write sio.string
86:       end
87:     end
88: 
89:     self
90:   end
add_metadata() click to toggle source

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

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

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 124
124:   def add_signatures
125:     if @data_signature then
126:       @tar_writer.add_file 'data.tar.gz.sig', 0644 do |io|
127:         io.write @data_signature
128:       end
129:     end
130: 
131:     if @meta_signature then
132:       @tar_writer.add_file 'metadata.gz.sig', 0644 do |io|
133:         io.write @meta_signature
134:       end
135:     end
136:   end
close() click to toggle source

Closes the TarOutput.

     # File lib/rubygems/package/tar_output.rb, line 141
141:   def close
142:     @tar_writer.close
143:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.