Class: RAR::Archive

Inherits:
Object
  • Object
show all
Defined in:
library/rar/archive.rb

Overview

The Archive class.

It is the main entry-point to creating a new archive.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ Archive

Create a new archive.

Parameters:

  • filename (String)

    The archive’s file name.

  • options (CommandLineOptions, optional) (defaults to: {})

    The options to pass to the command line.

Options Hash (options):

  • :extra (String)

    A string of command line options that will be passed directly to the command line.

  • :force (Boolean)

    Assume Yes on all queries.

  • :old_format (Boolean)

    Use the old style volume naming scheme.

  • :volume_size (Fixnum, String)

    The volume size in case of multiple volumes.

  • :compression (Fixnum)

    Set compression level. (0-store…3-default…5-maximal)

  • :exclude_path (Boolean)

    Exclude paths from names.



30
31
32
33
34
# File 'library/rar/archive.rb', line 30

def initialize filename, options = {}
  @files = []
  @options = CommandLineOptions.new.merge options
  @filename = filename
end

Instance Attribute Details

#filesArray

Returns the list of files.

Returns:

  • (Array)

    the list of files.



9
10
11
# File 'library/rar/archive.rb', line 9

def files
  @files
end

#optionsHash

Returns the list of options.

Returns:

  • (Hash)

    the list of options.



12
13
14
# File 'library/rar/archive.rb', line 12

def options
  @options
end

Instance Method Details

#add_file(path) ⇒ Array

Add a file to the list of files.

Returns:

  • (Array)

    the list of files.

Raises:

  • ERRNO::ENOENT if the file doesn’t exist.



40
41
42
43
44
45
46
# File 'library/rar/archive.rb', line 40

def add_file path
  if File.exist? path
    @files << path
  else
    raise Errno::ENOENT, "File '#{path}' doesn't exist"
  end
end

#create!Object

Create the final archive.

Returns:

  • true if the command executes without a hitch.

Raises:

  • CommandLineError if the exit code indicates an error.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'library/rar/archive.rb', line 52

def create!
  rar_process = IO.popen command_line

  # Wait for the child rar process to finish.
  _, status = Process.wait2 rar_process.pid

  if status.exitstatus > 1
    if message = ExitCodeMessages[status.exitstatus]
      raise CommandLineError, message
    else
      raise CommandLineError, "Unknown exit status: #{status}"
    end
  else
    true
  end
end