Class: Omnizip::ArchiveHandlers::TarHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/archive_handlers/tar_handler.rb

Overview

Adapter that exposes the canonical +create+/+open+/+extract_to+ /+list+ interface for the TAR format. Wraps Omnizip::Formats::Tar.

Instance Method Summary collapse

Instance Method Details

#create(path, &block) ⇒ Object



8
9
10
# File 'lib/omnizip/archive_handlers/tar_handler.rb', line 8

def create(path, &block)
  Omnizip::Formats::Tar.create(path, &block)
end

#extract_to(path, output_dir, **_) ⇒ Object



16
17
18
# File 'lib/omnizip/archive_handlers/tar_handler.rb', line 16

def extract_to(path, output_dir, **_)
  Omnizip::Formats::Tar.extract(path, output_dir)
end

#list(path, details: false, **_) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/omnizip/archive_handlers/tar_handler.rb', line 20

def list(path, details: false, **_)
  entries = Omnizip::Formats::Tar.list(path)
  if details
    entries.map do |entry|
      {
        name: entry.name,
        size: entry.size,
        directory: entry.directory?,
        mtime: entry.mtime,
        mode: entry.mode,
      }
    end
  else
    entries.map(&:name)
  end
end

#open(path, &block) ⇒ Object



12
13
14
# File 'lib/omnizip/archive_handlers/tar_handler.rb', line 12

def open(path, &block)
  Omnizip::Formats::Tar.open(path, &block)
end

#read_entry(path, entry_name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/omnizip/archive_handlers/tar_handler.rb', line 37

def read_entry(path, entry_name)
  data = nil
  Omnizip::Formats::Tar.open(path) do |reader|
    entry = reader.entries.find { |e| e.name == entry_name }
    raise Errno::ENOENT, "Entry not found: #{entry_name}" unless entry

    data = entry.data
  end
  data
end