Created
September 26, 2020 19:57
-
-
Save JoshAshby/4cb601765f958c15d34429540672b9a3 to your computer and use it in GitHub Desktop.
Quick and dirty utility to extract a unitypackage's contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rubygems/package' | |
require 'zlib' | |
require 'fileutils' | |
require 'pathname' | |
def unpack filename, output | |
output_path = Pathname.new output | |
Zlib::GzipReader.open filename do |gz| | |
Gem::Package::TarReader.new gz do |tar| | |
directories = tar.filter(&:directory?) | |
puts "found #{directories.length} dirs" | |
directories.each do |dir| | |
puts "attempting to open #{dir.full_name}" | |
pathname = "" | |
asset = "" | |
tar.seek(dir.full_name + "pathname") do |pathname_file| | |
pathname = pathname_file.read | |
puts "found pathname file #{pathname}" | |
end | |
tar.seek(dir.full_name + "asset") do |asset_file| | |
asset = asset_file.read | |
puts "found asset file" | |
end | |
next if asset.empty? || pathname.empty? | |
path = output_path.join pathname | |
puts "writing to #{path.to_s}" | |
path.dirname.mkpath | |
path.open "w+" do |asset_file| | |
asset_file.write asset | |
end | |
end | |
end | |
end | |
end | |
puts "Unpacking unitypackage #{ARGV[0]} to #{ARGV[1]}" | |
unpack ARGV[0], ARGV[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment