Last active
March 16, 2018 04:11
-
-
Save bacongravy/586d66ec37f28cf03fbe6599744bfbcf to your computer and use it in GitHub Desktop.
Creates a gzipped tar archive using vanilla Ruby and no temporary files
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/package' | |
filenames_and_contents = { | |
"filename" => "content", | |
} | |
File.open("archive.tar.gz", "wb") do |file| | |
Zlib::GzipWriter.wrap(file) do |gzip| | |
Gem::Package::TarWriter.new(gzip) do |tar| | |
filenames_and_contents.each_pair do |filename, content| | |
tar.add_file_simple(filename, 0644, content.length) do |io| | |
io.write(content) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment