Sha256: ed57b00829ea0ad4e680b6a4185d97b06e92b3bc824904a58832833c86fb92d9

Contents?: true

Size: 779 Bytes

Versions: 5

Compression:

Stored size: 779 Bytes

Contents

class PgExport
  class CompressDump
    include Logging

    def initialize(dump)
      @dump = dump
    end

    def call
      validate_dumpfile_exists
      compress_dumpfile
      remove_dumpfile
      self
    end

    private

    attr_reader :dump

    def validate_dumpfile_exists
      File.exist?(dump.pathname) or raise DumpFileDoesNotExistError, "#{dump.pathname} does not exist"
    end

    def compress_dumpfile
      Zlib::GzipWriter.open(dump.pathname_gz) do |gz|
        File.open(dump.pathname) do |fp|
          while chunk = fp.read(16 * 1024)
            gz.write chunk
          end
        end
      end
      logger.info "Zip dump #{dump.basename_gz} (#{dump.size_gz})"
    end

    def remove_dumpfile
      File.delete(dump.pathname)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_export-0.2.0 lib/pg_export/actions/compress_dump.rb
pg_export-0.1.3 lib/pg_export/actions/compress_dump.rb
pg_export-0.1.2 lib/pg_export/actions/compress_dump.rb
pg_export-0.1.1 lib/pg_export/actions/compress_dump.rb
pg_export-0.1.0 lib/pg_export/actions/compress_dump.rb