- require 'zlib'
- file = 'compressed.gz'
- Zlib::GzipWriter.open(file) do |gzip|
- gzip << "this is a test."
- gzip.close
- end
- open('compressed.gz', 'wb') do |file|
- gzip = Zlib::GzipWriter.new(file)
- gzip << "this is a test."
- gzip.close
- end
- #该片段来自于http://www.codesnippet.cn/detail/250220132217.html
来源: http://www.codesnippet.cn/detail/250220132217.html