Class: Gemvault::Tarball

Inherits:
Object
  • Object
show all
Defined in:
lib/gemvault/tarball.rb

Overview

The tar file backing a Tarvault. Reads named members 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

Constructor Details

#initialize(path) ⇒ Tarball

Returns a new instance of Tarball.



11
12
13
# File 'lib/gemvault/tarball.rb', line 11

def initialize(path)
  @path = Pathname(path)
end

Instance Method Details

#entriesObject



19
20
21
# File 'lib/gemvault/tarball.rb', line 19

def entries
  each_entry.map { |member| ArchiveEntry.new(name: member.full_name, bytes: member.read) }
end

#read(name) ⇒ Object



15
16
17
# File 'lib/gemvault/tarball.rb', line 15

def read(name)
  entries.find { |entry| entry.name == name }&.bytes
end

#write(entries) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/gemvault/tarball.rb', line 23

def write(entries)
  Tempfile.create(["tarvault", ".tar"], @path.dirname) do |tmp|
    write_entries(io: tmp, entries:)
    tmp.flush
    tmp.fsync
    tmp.close
    Pathname(tmp.path).rename(@path)
  end
end