class Archive::Extract
Extraction OOP interface for Archive
. See ::new
and extract
for more information.
Attributes
dir[R]
The extraction directory target. See ::new
.
filename[R]
The filename of the compressed archive. See ::new
.
Public Class Methods
new(filename, dir=Dir.pwd)
click to toggle source
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.
# 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
Public Instance Methods
extract(verbose=false)
click to toggle source
Perform the extraction. Takes an optional value that when true prints each filename extracted to stdout.
# File lib/archive/extract.rb, line 45 def extract(verbose=false) create_io_objects open_file header_loop(verbose) close end