Class: Archive::Tar::Minitar::Output
- Inherits:
-
Object
- Object
- Archive::Tar::Minitar::Output
- Defined in:
- lib/archive/tar/minitar/output.rb
Overview
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 Writer#add_file_simple and Writer#mkdir are guaranteed to work.
Instance Attribute Summary collapse
-
#tar ⇒ Object
readonly
Returns the Writer object for direct access.
Class Method Summary collapse
-
.open(output) ⇒ Object
With no associated block,
Output.open
is a synonym forOutput.new
. -
.tar(output) ⇒ Object
Output.tar is a wrapper for Output.open that yields the owned tar object instead of the Output object.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the Writer object and the wrapped data stream.
-
#closed? ⇒ Boolean
Returns false if the wrapped data stream is open.
-
#initialize(output) ⇒ Output
constructor
Creates a new Output object.
Constructor Details
#initialize(output) ⇒ Output
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 Output#close is called, the stream object wrapped will be closed.
call-seq:
Archive::Tar::Minitar::Output.new(io) -> output
Archive::Tar::Minitar::Output.new(path) -> output
56 57 58 59 60 61 62 63 |
# File 'lib/archive/tar/minitar/output.rb', line 56 def initialize(output) @io = if output.respond_to?(:write) output else ::Kernel.open(output, 'wb') end @tar = Archive::Tar::Minitar::Writer.new(@io) end |
Instance Attribute Details
#tar ⇒ Object (readonly)
Returns the Writer object for direct access.
66 67 68 |
# File 'lib/archive/tar/minitar/output.rb', line 66 def tar @tar end |
Class Method Details
.open(output) ⇒ Object
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.
call-seq:
Archive::Tar::Minitar::Output.open(io) -> output
Archive::Tar::Minitar::Output.open(io) { |output| block } -> obj
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/archive/tar/minitar/output.rb', line 20 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(output) ⇒ Object
Output.tar is a wrapper for Output.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.
call-seq:
Archive::Tar::Minitar::Output.tar(io) -> enumerator
Archive::Tar::Minitar::Output.tar(io) { |tar| block } -> obj
40 41 42 43 44 45 46 |
# File 'lib/archive/tar/minitar/output.rb', line 40 def self.tar(output) return to_enum(__method__, output) unless block_given? open(output) do |stream| yield stream.tar end end |
Instance Method Details
#close ⇒ Object
Closes the Writer object and the wrapped data stream.
74 75 76 77 |
# File 'lib/archive/tar/minitar/output.rb', line 74 def close @tar.close @io.close end |
#closed? ⇒ Boolean
Returns false if the wrapped data stream is open.
69 70 71 |
# File 'lib/archive/tar/minitar/output.rb', line 69 def closed? @io.closed? end |