class Archive::Compress

Compression OOP interface for Archive. See ::new and compress for more information.

Constants

BUFSIZE

The buffer size for reading content.

Attributes

compression[R]

the compression type of the archive. See ::new.

filename[R]

the filename of the compressed archive

type[R]

the type of the archive. See ::new.

Public Class Methods

new(filename, args={ :type => :tar, :compression => :gzip }) click to toggle source

Create a new Compress object. Takes a filename as string, and args as hash.

args is a hash that contains two values, :type and :compression.

  • :type may be :tar or :zip

  • :compression may be :gzip, :bzip2, or nil (no compression)

If the type :zip is selected, no compression will be used. Additionally, files in the .zip will all be stored as binary files.

The default set of arguments is

{ :type => :tar, :compression => :gzip }
# File lib/archive/compress.rb, line 34
def initialize(filename, args={ :type => :tar, :compression => :gzip })
  @filename     = filename
  @type         = args[:type] || :tar
  @compression  = args[:compression]

  if type == :zip
    @compression = nil
  end
end

Public Instance Methods

compress(files, verbose=false) click to toggle source

Run the compression. Files are an array of filenames. Optional flag for verbosity; if true, will print each file it adds to the archive to stdout.

Files must be real files. No symlinks, directories, unix sockets, character devices, etc. This method will raise ArgumentError if you provide any.

# File lib/archive/compress.rb, line 53
def compress(files, verbose=false)
  if files.any? { |f| !File.file?(f) }
    raise ArgumentError, "Files supplied must all be real, actual files -- not directories or symlinks."
  end

  configure_archive
  compress_files(files, verbose)
  free_archive
end