Created
December 27, 2020 07:42
-
-
Save mryoshio/67feb0704878a2b9d145b8b39017ef89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def generate_tgz(filepath, contents) | |
tar = StringIO.new | |
Gem::Package::TarWriter.new(tar) do |writer| | |
writer.add_file(filepath, 0600) do |f| | |
f.write(contents) | |
end | |
end | |
tar.seek(0) | |
gz = Zlib::GzipWriter.open("#{filepath}.tar.gz") do |gz| | |
gz.write(tar.read) | |
end | |
tar.close | |
"#{filepath}.tar.gz" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment