lib/archive/tar/minitar/output.rb in minitar-0.6 vs lib/archive/tar/minitar/output.rb in minitar-0.6.1
- old
+ new
@@ -18,13 +18,18 @@
# Archive::Tar::Minitar::Output.open(io) -> output
# Archive::Tar::Minitar::Output.open(io) { |output| block } -> obj
def self.open(output)
stream = new(output)
return stream unless block_given?
- yield stream
- ensure
- stream.close
+
+ # 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
# 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.
@@ -57,9 +62,14 @@
@tar = Archive::Tar::Minitar::Writer.new(@io)
end
# Returns the Writer object for direct access.
attr_reader :tar
+
+ # Returns false if the wrapped data stream is open.
+ def closed?
+ @io.closed?
+ end
# Closes the Writer object and the wrapped data stream.
def close
@tar.close
@io.close