Class: Omnizip::ArchiveHandlers::SevenZipHandler
- Inherits:
-
Object
- Object
- Omnizip::ArchiveHandlers::SevenZipHandler
- 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
-
#create(path, &block) ⇒ Object
Creates a .7z archive.
- #extract_to(path, output_dir, **options) ⇒ Object
- #list(path, details: false, **options) ⇒ Object
- #read_entry(path, entry_name, **options) ⇒ Object
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, **) Omnizip::Formats::SevenZip.open(path, ) do |reader| reader.extract_all(output_dir) end end |
#list(path, details: false, **options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/omnizip/archive_handlers/seven_zip_handler.rb', line 23 def list(path, details: false, **) with_reader(path, ) do |reader| entries = reader.list_files if details entries.map do |e| { name: e.name, size: e.size, directory: e.is_dir, mtime: e.mtime } end else entries.map(&:name) end end end |
#read_entry(path, entry_name, **options) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/omnizip/archive_handlers/seven_zip_handler.rb', line 37 def read_entry(path, entry_name, **) with_reader(path, ) do |reader| entry = reader.list_files.find { |e| e.name == entry_name } raise Errno::ENOENT, "Entry not found: #{entry_name}" unless entry reader.extract_entry_data(File.open(path, "rb"), entry) end end |