lib/backup/jar.rb in encbs-0.1.0 vs lib/backup/jar.rb in encbs-0.1.1

- old
+ new

@@ -1,12 +1,13 @@ module Backup class Jar - def initialize(file_item, root_path, local_path) + def initialize(file_item, root_path, local_path, key = nil) @root_path = root_path @local_path = local_path @timestamp = Backup::Timestamp.create @file_item = file_item + @key = key end def jar_hash Digest::MD5.hexdigest(@local_path) end @@ -71,11 +72,20 @@ pbar.bar_mark = '*' @local_files.keys.each do |file| unless Dir.exists?(file) - @file_item.create_file_once "#{jar_data_path}/#{@file_item.file_hash file}", - File.open(file) + data = if @key + @key.encrypt_to_stream(File.open(file).read) + else + File.open(file) + end + + @file_item.create_file_once( + "#{jar_data_path}/#{@file_item.file_hash file}", + data + ) + pbar.inc end end pbar.finish