Class: Archive::Tar::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/archive/tar/writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(filenames) ⇒ Writer

Returns a new instance of Writer.



5
6
7
8
9
10
# File 'lib/archive/tar/writer.rb', line 5

def initialize(filenames)
	@inodes = {}
	@records = {}
	@index = []
	filenames.each { |path| self << path }
end

Instance Method Details

#<<(filename) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/archive/tar/writer.rb', line 12

def <<(filename)
	@index << filename
	@records[filename] = Archive::Tar::Format.stat(filename, @inodes)
	if File.directory?(filename)
		Dir.open(filename) do |dh|
			dh.entries.each do |file|
				self << File.join(filename, file) unless [".",".."].include? file
			end
		end
	end
end

#write(dest, options = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/archive/tar/writer.rb', line 24

def write(dest, options = {})
	if dest.is_a? IO
		write_to(dest, options)
	else
		File.open(dest, 'w') { |io| write_to(io, options) }
	end
end