Class: Omnizip::Formats::Rar3::Reader

Inherits:
Omnizip::Formats::Rar::RarFormatBase show all
Defined in:
lib/omnizip/formats/rar3/reader.rb

Overview

RAR v3 (RAR4-family) archive reader

Adapter over the primary Formats::Rar::Reader — the one parser verified against real WinRAR archives — exposing the legacy entry shape (uncompressed_size, modified_time, ...).

Examples:

Reading a RAR3 archive

reader = Rar3::Reader.new
File.open("archive.rar", "rb") do |file|
  reader.read_archive(file).each { |entry| puts entry.name }
end

Defined Under Namespace

Classes: Entry

Constant Summary collapse

METHOD_SYMBOLS =

RAR4 method byte to the legacy symbol vocabulary

{
  0x30 => :store,
  0x31 => :fastest,
  0x32 => :fast,
  0x33 => :normal,
  0x34 => :good,
  0x35 => :best,
}.freeze

Instance Attribute Summary

Attributes inherited from Omnizip::Formats::Rar::RarFormatBase

#spec, #version

Instance Method Summary collapse

Methods inherited from Omnizip::Formats::Rar::RarFormatBase

#block_type_code, #block_type_name, #compress, #compression_method_code, #compression_method_name, #decompress, #dictionary_size_code, #encryption_algorithm, #supports_feature?, #verify_magic_bytes, #write_archive

Constructor Details

#initializeReader

Initialize a RAR v3 reader



32
33
34
# File 'lib/omnizip/formats/rar3/reader.rb', line 32

def initialize
  super("rar3")
end

Instance Method Details

#read_archive(io) ⇒ Array<Entry>

Read a RAR v3 archive

Parameters:

  • io (IO)

    The input stream

Returns:

  • (Array<Entry>)

    The archive entries

Raises:

  • (FormatError)

    If the archive signature is invalid



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/omnizip/formats/rar3/reader.rb', line 41

def read_archive(io)
  data = io.read
  unless verify_magic_bytes(StringIO.new(data))
    raise FormatError, "Invalid RAR v3 signature"
  end

  Dir.mktmpdir("omnizip_rar3_read") do |tmp|
    archive_path = File.join(tmp, "archive.rar")
    File.binwrite(archive_path, data)

    primary = Rar::Reader.new(archive_path)
    primary.open
    primary.list_files.map { |entry| adapt_entry(entry) }
  end
end