Class: ZKSync::Archive

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(passphrase, fs_base_path, root) ⇒ Archive

Returns a new instance of Archive.



22
23
24
25
26
27
# File 'lib/zksync/archive.rb', line 22

def initialize(passphrase, fs_base_path, root)
  @root = root
  @fs_base_path = fs_base_path
  @keystore = KeyStore.new(Key.new(passphrase, type: :passphrase))
  @file_index = CryptoFileIndex.new("@@index", self)
end

Instance Attribute Details

#file_indexObject (readonly)

Returns the value of attribute file_index.



20
21
22
# File 'lib/zksync/archive.rb', line 20

def file_index
  @file_index
end

#fs_base_pathObject (readonly)

Returns the value of attribute fs_base_path.



20
21
22
# File 'lib/zksync/archive.rb', line 20

def fs_base_path
  @fs_base_path
end

#keystoreObject (readonly)

Returns the value of attribute keystore.



20
21
22
# File 'lib/zksync/archive.rb', line 20

def keystore
  @keystore
end

#rootObject (readonly)

Returns the value of attribute root.



20
21
22
# File 'lib/zksync/archive.rb', line 20

def root
  @root
end

Instance Method Details

#add(fs_paths) ⇒ Object

add fs-paths to the archive. returns array of paths that were not added successfully. archive paths are stored relative to basepath



31
32
33
34
35
# File 'lib/zksync/archive.rb', line 31

def add(fs_paths)
  [*fs_paths]
    .map { |fs_path| File.expand_path(fs_path) }
    .reject { |fs_path| add_file(fs_path) }
end

#add_file(fs_path) ⇒ Object



60
61
62
63
# File 'lib/zksync/archive.rb', line 60

def add_file(fs_path)
  archive_path = Pathname.new(fs_path).relative_path_from(Pathname.new(fs_base_path)).to_s
  @file_index.add(archive_path, fs_path)
end

#commitObject



46
47
48
# File 'lib/zksync/archive.rb', line 46

def commit
  @file_index.write
end

#file_at_path(archive_path) ⇒ Object



50
51
52
# File 'lib/zksync/archive.rb', line 50

def file_at_path(archive_path)
  @file_index.file_at_path(archive_path)
end

#inode_for_path(archive_path) ⇒ Object



54
55
56
# File 'lib/zksync/archive.rb', line 54

def inode_for_path(archive_path)
  @file_index.inode_for_path(archive_path)
end

#listObject

list of all archive paths in this archive



38
39
40
# File 'lib/zksync/archive.rb', line 38

def list
  @file_index.list
end

#rm(*archive_paths) ⇒ Object



42
43
44
# File 'lib/zksync/archive.rb', line 42

def rm(*archive_paths)
  archive_paths.each { |archive_path| @file_index.rm(archive_path) }
end