Class: Gemvault::TarArchive
- Inherits:
-
Object
- Object
- Gemvault::TarArchive
- Defined in:
- lib/gemvault/tar_archive.rb
Overview
The tar file backing a Tarvault. Reads named entries and rewrites the whole archive atomically: tar has no index and the leading manifest entry changes size on every mutation, so mutation means a full rewrite.
Instance Method Summary collapse
- #gem_pairs ⇒ Object
-
#initialize(path) ⇒ TarArchive
constructor
A new instance of TarArchive.
- #read(name) ⇒ Object
- #write(pairs) ⇒ Object
Constructor Details
#initialize(path) ⇒ TarArchive
Returns a new instance of TarArchive.
11 12 13 |
# File 'lib/gemvault/tar_archive.rb', line 11 def initialize(path) @path = path end |
Instance Method Details
#gem_pairs ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/gemvault/tar_archive.rb', line 21 def gem_pairs pairs = [] each_entry do |entry| pairs << [entry.full_name, entry.read] unless entry.full_name == Manifest::FILENAME end pairs end |
#read(name) ⇒ Object
15 16 17 18 19 |
# File 'lib/gemvault/tar_archive.rb', line 15 def read(name) bytes = nil each_entry { |entry| bytes = entry.read if entry.full_name == name } bytes end |
#write(pairs) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gemvault/tar_archive.rb', line 29 def write(pairs) tmp = Tempfile.create(["tarvault", ".tar"], File.dirname(@path)) write_entries(tmp, pairs) tmp.flush tmp.fsync tmp.close File.rename(tmp.path, @path) rescue StandardError cleanup(tmp) raise end |