Sha256: 78abfd8e6863114a64917f951b2af4ae6e61344ed619fb57592a53ad5596bf97
Contents?: true
Size: 1.11 KB
Versions: 17
Compression:
Stored size: 1.11 KB
Contents
module Workspace class WorkspaceFile module Archive extend ActiveSupport::Concern def extract(target_dir) target_dir.create if extension == "zip" extract_zip(target_dir) elsif extension == "gz" extract_gz(target_dir) end self end private def extract_zip(target_dir) require "zip" Zip::File.open(to_s) do |archive| archive.each do |entry| entry.extract(File.join(target_dir.to_s, entry.name)) end end end def extract_gz(target_dir) require 'rubygems/package' workspace_dir = target_dir.root_dir archive = Gem::Package::TarReader.new(Zlib::GzipReader.open(to_s)) archive.rewind archive.each do |entry| if entry.directory? archive_dir = workspace_dir.dir(entry.full_name) archive_dir.create elsif entry.file? archive_file = workspace_dir.file(entry.full_name) archive_file.write(entry.read) end end archive.close end end end end
Version data entries
17 entries across 17 versions & 1 rubygems