Class: Zlib::GzipWriter

Inherits:
GzipFile show all
Defined in:
zlib.c,
zlib.c

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GzipFile

#close, #closed?, #comment, #crc, #finish, #level, #mtime, #orig_name, #os_code, #sync, #sync=, #to_io, wrap

Constructor Details

#Zlib::GzipWriter.new(io, level, strategy) ⇒ Object

Creates a GzipWriter object associated with io. level and strategy should be the same as the arguments of Zlib::Deflate.new. The GzipWriter object writes gzipped data to io. At least, io must respond to the write method that behaves same as write method in IO class.



2715
2716
2717
# File 'zlib.c', line 2715

static VALUE
rb_gzwriter_initialize(argc, argv, obj)
int argc;

Class Method Details

.Zlib::GzipWriter.open(filename, level = nil, strategy = nil) {|gz| ... } ⇒ Object

Opens a file specified by filename for writing gzip compressed data, and returns a GzipWriter object associated with that file. Further details of this method are found in Zlib::GzipWriter.new and Zlib::GzipWriter#wrap.

Yields:

  • (gz)


2698
2699
2700
# File 'zlib.c', line 2698

static VALUE
rb_gzwriter_s_open(argc, argv, klass)
int argc;

Instance Method Details

#<<Object

Same as IO.

#comment=Object

???



2525
2526
2527
# File 'zlib.c', line 2525

static VALUE
rb_gzfile_set_comment(obj, str)
VALUE obj, str;

#flush(flush = nil) ⇒ Object

Flushes all the internal buffers of the GzipWriter object. The meaning of flush is same as in Zlib::Deflate#deflate. Zlib::SYNC_FLUSH is used if flush is omitted. It is no use giving flush Zlib::NO_FLUSH.



2748
2749
2750
# File 'zlib.c', line 2748

static VALUE
rb_gzwriter_flush(argc, argv, obj)
int argc;

#mtime=Object

???



2478
2479
2480
# File 'zlib.c', line 2478

static VALUE
rb_gzfile_set_mtime(obj, mtime)
VALUE obj, mtime;

#orig_name=Object

???



2502
2503
2504
# File 'zlib.c', line 2502

static VALUE
rb_gzfile_set_orig_name(obj, str)
VALUE obj, str;

#posObject

???



2636
2637
2638
# File 'zlib.c', line 2636

static VALUE
rb_gzfile_total_in(obj)
VALUE obj;

Same as IO.

#printfObject

Same as IO.

#putcObject

Same as IO.



2791
2792
2793
# File 'zlib.c', line 2791

static VALUE
rb_gzwriter_putc(obj, ch)
VALUE obj, ch;

#putsObject

Same as IO.

#tellObject

???



2636
2637
2638
# File 'zlib.c', line 2636

static VALUE
rb_gzfile_total_in(obj)
VALUE obj;

#writeObject

Same as IO.



2775
2776
2777
# File 'zlib.c', line 2775

static VALUE
rb_gzwriter_write(obj, str)
VALUE obj, str;