Class: Archive::Tar::Minitar::Output
- Inherits:
-
Object
- Object
- Archive::Tar::Minitar::Output
- Defined in:
- lib/folio/minitar.rb
Overview
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.
Class Method Summary collapse
-
.open(output) ⇒ Object
With no associated block,
Output::openis a synonym forOutput::new.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the Writer object and the wrapped data stream.
-
#initialize(output) ⇒ Output
constructor
Creates a new Output object.
-
#tar ⇒ Object
Returns the Writer object for direct access.
Constructor Details
#initialize(output) ⇒ Output
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.
890 891 892 893 894 895 896 897 |
# File 'lib/folio/minitar.rb', line 890 def initialize(output) if output.respond_to?(:write) @io = output else @io = ::File.open(output, "wb") end @tarwriter = Archive::Tar::Minitar::Writer.new(@io) 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 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.
873 874 875 876 877 878 879 880 881 882 883 884 |
# File 'lib/folio/minitar.rb', line 873 def self.open(output) stream = Output.new(output) return stream unless block_given? begin res = yield stream ensure stream.close end res end |
Instance Method Details
#close ⇒ Object
Closes the Writer object and the wrapped data stream.
905 906 907 908 |
# File 'lib/folio/minitar.rb', line 905 def close @tarwriter.close @io.close end |
#tar ⇒ Object
Returns the Writer object for direct access.
900 901 902 |
# File 'lib/folio/minitar.rb', line 900 def tar @tarwriter end |