Skip to content

Instantly share code, notes, and snippets.

@bacongravy
Last active March 16, 2018 04:11
Show Gist options
  • Save bacongravy/586d66ec37f28cf03fbe6599744bfbcf to your computer and use it in GitHub Desktop.
Save bacongravy/586d66ec37f28cf03fbe6599744bfbcf to your computer and use it in GitHub Desktop.
Creates a gzipped tar archive using vanilla Ruby and no temporary files
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