Class: Omnizip::ArchiveHandlers::SevenZipHandler

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

Overview

Adapter that exposes the canonical +create+/+extract_to+/+list+ interface for the 7z format. Wraps Omnizip::Formats::SevenZip.

Defined Under Namespace

Classes: FileProxy

Instance Method Summary collapse

Instance Method Details

#create(path, &block) ⇒ Object

Creates a .7z archive. The yielded proxy only supports add(name, source_path) for files — directory entries are not part of the single-file convenience flow.



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

def create(path, &block)
  Omnizip::Formats::SevenZip.create(path) do |writer|
    block&.call(FileProxy.new(writer))
  end
end

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



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

def extract_to(path, output_dir, **options)
  Omnizip::Formats::SevenZip.open(path, options) do |reader|
    reader.extract_all(output_dir)
  end
end

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



23
24
25
26
27
28
# File 'lib/omnizip/archive_handlers/seven_zip_handler.rb', line 23

def list(path, details: false, **options)
  Omnizip::Formats::SevenZip.open(path, options) do |reader|
    files = reader.list_files
    return details ? files.map { |f| { name: f } } : files
  end
end

#read_entry(_path, _entry_name) ⇒ Object

Raises:

  • (NotImplementedError)


30
31
32
33
34
# File 'lib/omnizip/archive_handlers/seven_zip_handler.rb', line 30

def read_entry(_path, _entry_name)
  raise NotImplementedError,
        "read_from_archive for .7z is not wired; use " \
        "Formats::SevenZip.open"
end