Wraps a Archive::Tar::Minitar::Writer with convenience methods and wrapped stream management. If the stream provided to Output does not support random access, only Archive::Tar::Minitar::Writer#add_file_simple and Archive::Tar::Minitar::Writer#mkdir are guaranteed to work.
Returns the Writer object for direct access.
Creates a new Output object. If
output
is a stream object that responds to write, then it will
simply be wrapped. Otherwise, one will be created and opened using
Kernel#open. When #close is
called, the stream object wrapped will be closed.
# File lib/archive/tar/minitar/output.rb, line 55 def initialize(output) @io = if output.respond_to?(:write) output else ::Kernel.open(output, 'wb') end @tar = Archive::Tar::Minitar::Writer.new(@io) end
With no associated block, Output.open
is a synonym for
Output.new
. If the optional code block is given, it will be
given the new Output as an argument and the Output object will automatically be closed when the
block terminates (this also closes the wrapped stream object). In this
instance, Output.open
returns the value of the block.
# File lib/archive/tar/minitar/output.rb, line 19 def self.open(output) stream = new(output) return stream unless block_given? # This exception context must remain, otherwise the stream closes on open # even if a block is not given. begin yield stream ensure stream.close end end
::tar is a wrapper for ::open that yields the owned tar object instead of the Output object. If a block is not provided, an enumerator will be created with the same behaviour.
# File lib/archive/tar/minitar/output.rb, line 39 def self.tar(output) return to_enum(__method__, output) unless block_given? open(output) do |stream| yield stream.tar end end
Closes the Writer object and the wrapped data stream.
# File lib/archive/tar/minitar/output.rb, line 73 def close @tar.close @io.close end
Returns false if the wrapped data stream is open.
# File lib/archive/tar/minitar/output.rb, line 68 def closed? @io.closed? end