Sha256: ed70f03fc93ef333d943f93958f76c02c55716f5ab1c891ac908dc60cb142202

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8

module Backup
  module Compressor
    class Bzip2 < Base

      ##
      # Tells Backup::Compressor::Bzip2 to compress
      # better (-9) rather than faster when set to true
      attr_writer :best

      ##
      # Tells Backup::Compressor::Bzip2 to compress
      # faster (-1) rather than better when set to true
      attr_writer :fast

      ##
      # Creates a new instance of Backup::Compressor::Bzip2 and
      # configures it to either compress faster or better
      # bzip2 compresses by default with -9 (best compression)
      # and lower block sizes don't make things significantly faster
      # (according to official bzip2 docs)
      def initialize(&block)
        load_defaults!

        @best ||= false
        @fast ||= false

        instance_eval(&block) if block_given?
      end

      ##
      # Performs the compression of the packages backup file
      def perform!
        log!
        run("#{ utility(:bzip2) } #{ options } '#{ Backup::Model.file }'")
        Backup::Model.extension += '.bz2'
      end

    private

      ##
      # Combines the provided options and returns a bzip2 options string
      def options
        (best + fast).join("\s")
      end

      ##
      # Returns the bzip2 option syntax for compressing
      # setting @best to true is redundant, as bzip2 compresses best by default
      def best
        return ['--best'] if @best; []
      end

      ##
      # Returns the bzip2 option syntax for compressing
      # (not significantly) faster when @fast is set to true
      def fast
        return ['--fast'] if @fast; []
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
backup-3.0.20 lib/backup/compressor/bzip2.rb
backup-3.0.19 lib/backup/compressor/bzip2.rb
backup-3.0.18 lib/backup/compressor/bzip2.rb
interu-backup-3.0.16 lib/backup/compressor/bzip2.rb
backup-3.0.16 lib/backup/compressor/bzip2.rb