Sha256: 889717e109588f95d99e24e5f1779e73c824a0094db9d4231592e6015939b3c8
Contents?: true
Size: 1.26 KB
Versions: 35
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true require 'eac_fs/file_info' require 'eac_ruby_utils/core_ext' module EhbrsRubyUtils module Fs class CompressedPackage < ::EacFs::FileInfo MIME_TYPES = { 'application/zip' => :zip, 'application/x-7z-compressed' => :sevenzip, 'application/x-rar' => :rar, 'application/x-tar' => :tar }.freeze def extract_to(target) target = target.to_pathname target.mkpath sub_extract_to(target) end private def sub_extract_to(target) MIME_TYPES[content_type.mime_type].if_present do |v| return send("#{v}_extract_command", target).execute! end raise "Unknown how to extract \"#{path}\" (#{content_type})" end def sevenzip_extract_command(target_dir) ::Ehbrs::Executables.sevenzip.command('x', path, '-o', target_dir) end def tar_extract_command(target_dir) ::Ehbrs::Executables.tar.command('-xf', path, '-C', target_dir) end def rar_extract_command(target_dir) ::Ehbrs::Executables.rar.command('x', path.expand_path).chdir(target_dir) end def zip_extract_command(target_dir) ::Ehbrs::Executables.unzip.command(path, '-d', target_dir) end end end end
Version data entries
35 entries across 35 versions & 2 rubygems