class TarWriter::Folder

Public Class Methods

new(fnam, mode) click to toggle source
# File lib/tarwriter.rb, line 187
def initialize fnam, mode
  @tar = @dir = nil
  if fnam.nil? then
    @dir = '.'
  elsif File.directory?(fnam) then
    @dir = fnam
  elsif /^mkdir:/ === fnam then
    @dir = $'
    Dir.mkdir(@dir, 0755)
  else
    @tar = TarWriter.new(fnam, mode) 
  end
end
open(fnam, mode) { |folder| ... } click to toggle source
# File lib/tarwriter.rb, line 176
def Folder::open fnam, mode
  folder = Folder.new(fnam, mode)
  return folder unless block_given?
  begin
    yield folder
  ensure
    folder.close
  end
  fnam
end

Public Instance Methods

add(fnam, content, time = Time.now) click to toggle source
# File lib/tarwriter.rb, line 201
def add fnam, content, time = Time.now
  if @tar then
    @tar.add(fnam, content, time)
  else
    path = File.join(@dir, fnam)
    File.open(path, 'w') {|ofp| ofp.write content }
    fnam
  end
end
close() click to toggle source
# File lib/tarwriter.rb, line 215
def close
  @tar.close if @tar
end
flush() click to toggle source
# File lib/tarwriter.rb, line 211
def flush
  @tar.flush if @tar
end