class

Zlib::GzipWriter

v1_8_7_72 - Show latest stable - Superclass: Zlib::GzipFile

Zlib::GzipWriter is a class for writing gzipped files. GzipWriter should be used with an instance of IO, or IO-like, object.

For example:

  Zlib::GzipWriter.open('hoge.gz') do |gz|
    gz.write 'jugemu jugemu gokou no surikire...'
  end

  File.open('hoge.gz', 'w') do |f|
    gz = Zlib::GzipWriter.new(f)
    gz.write 'jugemu jugemu gokou no surikire...'
    gz.close
  end

  # TODO: test these.  Are they equivalent?  Can GzipWriter.new take a
  # block?

NOTE: Due to the limitation of Ruby’s finalizer, you must explicitly close GzipWriter objects by Zlib::GzipWriter#close etc. Otherwise, GzipWriter will be not able to write the gzip footer and will generate a broken gzip file.

Files

  • ext/zlib/zlib.c