Class: Omnizip::ArchiveHandlers::XarHandler

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

Overview

Read-only adapter for the XAR archive format: extraction and listing over the XML TOC. XAR writing exists at the format level but is not exposed through the convenience archive API.

Instance Method Summary collapse

Instance Method Details

#create(_path, **_options) ⇒ Object



11
12
13
14
15
# File 'lib/omnizip/archive_handlers/xar_handler.rb', line 11

def create(_path, **_options)
  raise Omnizip::UnsupportedFormatError,
        "xar archives cannot be created through the convenience " \
        "API; use Omnizip::Formats::Xar.create directly"
end

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



17
18
19
20
21
# File 'lib/omnizip/archive_handlers/xar_handler.rb', line 17

def extract_to(path, output_dir, **_)
  Omnizip::Formats::Xar.extract(path, output_dir)
  Dir.glob(File.join(output_dir, "**", "*"))
    .select { |f| File.file?(f) }
end

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



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/omnizip/archive_handlers/xar_handler.rb', line 23

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

#read_entry(path, entry_name, **_) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/omnizip/archive_handlers/xar_handler.rb', line 35

def read_entry(path, entry_name, **_)
  Dir.mktmpdir("omnizip-xar-entry") do |dir|
    Omnizip::Formats::Xar.extract(path, dir)
    dest = File.join(dir, entry_name)
    raise Errno::ENOENT, "Entry not found: #{entry_name}" unless
      File.exist?(dest)

    File.binread(dest)
  end
end