Sha256: 5d95b0226737c32f524486006d628864d560f239696ea7e1313031ea994f2eab

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module GeoConcerns
  module Processors
    module Zip
      extend ActiveSupport::Concern

      included do
        # Unzips a file, invokes a block, and then deletes the unzipped file(s).
        # Use to wrap processor methods for geo file formats that
        # are zipped before uploading.
        #
        # @param in_path [String] file input path
        # @param output_file [String] processor output file path
        def self.unzip(in_path, output_file)
          basename = File.basename(output_file, File.extname(output_file))
          zip_out_path = "#{File.dirname(output_file)}/#{basename}_out"
          execute "unzip -qq -j -d \"#{zip_out_path}\" \"#{in_path}\""
          yield zip_out_path
          FileUtils.rm_rf(zip_out_path)
        end

        # Zips a file or directory.
        #
        # @param in_path [String] file input path
        # @param output_file [String] output zip file
        def self.zip(in_path, output_file)
          execute "zip -j -qq -r \"#{output_file}\" \"#{in_path}\""
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geo_concerns-0.0.1 app/processors/geo_concerns/processors/zip.rb