Class: Archive::Extract

Inherits:
Object
  • Object
show all
Defined in:
lib/archive/extract.rb

Overview

Extraction OOP interface for Archive. See ::new and #extract for more information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, dir = Dir.pwd) ⇒ Extract

Create a new Extract object. Takes a filename as string containing the archive name, and a directory name as string containing the target path to extract to. The default target is the current directory.

If either the filename or directory name do not already exist, ArgumentError will be raised.

Extraction tries to preserve timestamps and permissions, but not uid/gid. Note that this is format-dependent – e.g., .zip files will always be extracted as mode 0777.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/archive/extract.rb', line 24

def initialize(filename, dir=Dir.pwd)
  unless File.exist?(filename)
    raise ArgumentError, "File '#{filename}' does not exist!"
  end

  unless File.directory?(dir)
    raise ArgumentError, "Directory '#{dir}' does not exist!"
  end

  @filename = filename
  @dir      = dir

  @extract_flags =
    LibArchive::ARCHIVE_EXTRACT_PERM |
    LibArchive::ARCHIVE_EXTRACT_TIME
end

Instance Attribute Details

#dirObject (readonly)

The extraction directory target. See ::new.



10
11
12
# File 'lib/archive/extract.rb', line 10

def dir
  @dir
end

#filenameObject (readonly)

The filename of the compressed archive. See ::new.



8
9
10
# File 'lib/archive/extract.rb', line 8

def filename
  @filename
end

Instance Method Details

#extract(verbose = false) ⇒ Object

Perform the extraction. Takes an optional value that when true prints each filename extracted to stdout.



45
46
47
48
49
50
51
52
# File 'lib/archive/extract.rb', line 45

def extract(verbose=false)
  create_io_objects
  open_file

  header_loop(verbose)

  close
end