def pack_files( manifest )
db = Amalgalite::Database.new( dbfile )
check_db( db )
max_width = manifest.collect{ |m| m.require_path.length }.sort.last
contents_column = db.schema.tables[ options[:table_name] ].columns[ options[:contents_column] ]
db.transaction do |trans|
manifest.each do |file_info|
msg = " -> #{file_info.require_path.ljust( max_width )} : "
begin
if options[:merge] then
trans.execute( "DELETE FROM #{options[:table_name]} WHERE #{options[:filename_column]} = ?", file_info.require_path )
end
trans.prepare("INSERT INTO #{options[:table_name]}(#{options[:filename_column]}, #{options[:compressed_column]}, #{options[:contents_column]}) VALUES( $filename, $compressed, $contents)") do |stmt|
contents = IO.readlines( file_info.file_path )
if options[:self] then
contents.each { |l| l.gsub!( /^(\s*require .*)$/m, "# commented out by #{self.class.name} \\1") }
end
contents = contents.join
if options[:compressed] then
contents = Packer.gzip( contents )
end
content_io = StringIO.new( contents )
stmt.execute( "$filename" => file_info.require_path,
"$contents" => Amalgalite::Blob.new( :io => content_io,
:column => contents_column ),
"$compressed" => options[:compressed] )
STDERR.puts "#{msg} stored #{file_info.file_path}" if options[:verbose]
end
rescue => e
STDERR.puts "#{msg} error #{e}"
end
end
end
end