class Archive::Tar::Minitar::Output
Wraps a Archive::Tar::Minitar::Writer
with convenience methods and wrapped stream management; Output
only works with random access data streams. See Output::new
for details.
Public Class Methods
Creates a new Output
object. If output
is a stream object that responds to read), then it will simply be wrapped. Otherwise, one will be created and opened using Kernel#open. When Output#close
is called, the stream object wrapped will be closed.
# File lib/archive/tar/minitar.rb 814 def initialize(output) 815 if output.respond_to?(:write) 816 @io = output 817 else 818 @io = ::File.open(output, "wb") 819 end 820 @tarwriter = Archive::Tar::Minitar::Writer.new(@io) 821 end
With no associated block, Output::open
is a synonym for Output::new
. If the optional code block is given, it will be passed the new writer as an argument and the Output
object will automatically be closed when the block terminates. In this instance, Output::open
returns the value of the block.
# File lib/archive/tar/minitar.rb 797 def self.open(output) 798 stream = Output.new(output) 799 return stream unless block_given? 800 801 begin 802 res = yield stream 803 ensure 804 stream.close 805 end 806 807 res 808 end
Public Instance Methods
Closes the Writer
object and the wrapped data stream.
# File lib/archive/tar/minitar.rb 829 def close 830 @tarwriter.close 831 @io.close 832 end
Returns the Writer
object for direct access.
# File lib/archive/tar/minitar.rb 824 def tar 825 @tarwriter 826 end