Sha256: fd9743a1ac6a99ba592d3605795f35d27c156758ea00415777520cb65ef063db

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8

module Backup
  module Compressor
    class Lzma < Base

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

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

      ##
      # Creates a new instance of Backup::Compressor::Lzma and
      # configures it to either compress faster or better
      # Lzma 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(:lzma) } #{ options } '#{ Backup::Model.file }'")
        Backup::Model.extension += '.lzma'
      end

    private

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

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

      ##
      # Returns the lzma 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

3 entries across 3 versions & 1 rubygems

Version Path
backup-3.0.20 lib/backup/compressor/lzma.rb
backup-3.0.19 lib/backup/compressor/lzma.rb
backup-3.0.18 lib/backup/compressor/lzma.rb