Class: Archive::Extract
- Inherits:
-
Object
- Object
- Archive::Extract
- Defined in:
- lib/archive/extract.rb
Overview
Extraction OOP interface for Archive. See ::new and #extract for more information.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
The extraction directory target.
-
#filename ⇒ Object
readonly
The filename of the compressed archive.
Instance Method Summary collapse
-
#extract(verbose = false) ⇒ Object
Perform the extraction.
-
#initialize(filename, dir = Dir.pwd) ⇒ Extract
constructor
Create a new Extract object.
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
#dir ⇒ Object (readonly)
The extraction directory target. See ::new.
10 11 12 |
# File 'lib/archive/extract.rb', line 10 def dir @dir end |
#filename ⇒ Object (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 |