Class: Omnizip::ArchiveHandlers::CpioHandler

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

Overview

Read-only adapter for the CPIO format (initramfs images, RPM payloads). Extraction and listing are supported; CPIO 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



12
13
14
15
16
# File 'lib/omnizip/archive_handlers/cpio_handler.rb', line 12

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

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



18
19
20
# File 'lib/omnizip/archive_handlers/cpio_handler.rb', line 18

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

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



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

def list(path, details: false, **_)
  entries = Omnizip::Formats::Cpio.list(path)
  if details
    entries.map do |e|
      { name: e.name, size: e.data.bytesize,
        directory: e.name.end_with?("/"), mtime: nil }
    end
  else
    entries.map(&:name)
  end
end

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



34
35
36
37
38
39
40
41
42
# File 'lib/omnizip/archive_handlers/cpio_handler.rb', line 34

def read_entry(path, entry_name, **_)
  entry = Omnizip::Formats::Cpio.list(path)
    .find { |e| e.name == entry_name }
  unless entry
    raise Errno::ENOENT, "Entry not found: #{entry_name}"
  end

  entry.data
end