Inputs ((|string|)) into the end of input buffer and
skips data until a full flush point can be found.
If the point is found in the buffer, this method flushes
the buffer and returns false. Otherwise it returns true
and the following data of full flush point is preserved
in the buffer.
Closes the GzipFile object. This method calls close method
of the associated IO object. Returns the associated IO object.
--- Zlib::GzipFile#finish
Closes the GzipFile object. Unlike ((<Zlib::GzipFile#close>)),
this method ((*never*)) calls close method of the associated IO
object. Returns the associated IO object.
--- Zlib::GzipFile#crc
Returns CRC value of the uncompressed data.
--- Zlib::GzipFile#level
Returns compression level.
--- Zlib::GzipFile#mtime
Returns last modification time recorded in the gzip
file header.
--- Zlib::GzipFile#os_code
Returns OS code number recorded in the gzip file header.
--- Zlib::GzipFile#orig_name
Returns original filename recorded in the gzip file header,
or nil if original filename is not present.
--- Zlib::GzipFile#comment
Returns comments recorded in the gzip file header, or
nil if the comments is not present.
--- Zlib::GzipFile#sync
--- Zlib::GzipFile#sync= flag
Same as IO. If ((|flag|)) is true, the associated IO object
must respond to flush method. While `sync' mode is true,
the compression ratio decreases sharply.
== Zlib::GzipFile::Error
The superclass for all exceptions raised during processing a gzip
file.
The following exceptions are defined as subclasses of
Zlib::GzipFile::Error.
: Zlib::GzipFile::NoFooter
Raised when gzip file footer has not found.
: Zlib::GzipFile::CRCError
Raised when the CRC checksum recorded in gzip file footer
is not equivalent to CRC checksum of the actually
uncompressed data.
: Zlib::GzipFile::LengthError
Raised when the data length recorded in gzip file footer
is not equivalent to length of the actually uncompressed data.
=== 超级类:
* ((<Zlib::Error>))
== Zlib::GzipReader
The class for reading a gzipped file. GzipReader should be used
with associating an instance of IO class (or an object which has
the same methods as IO has).
f = File.open('hoge.gz')
gz = Zlib::GzipReader.new(f)
print gz.read
gz.close
=== 超级类:
* ((<Zlib::GzipFile>))
=== 包含的模块:
* Enumerable
=== Class Methods:
--- Zlib::GzipReader.new(io)
Creates a GzipReader object associated with ((|io|)).
The GzipReader object reads gzipped data from ((|io|)),
and parses/decompresses them. At least, ((|io|)) must have
read method that behaves same as read method in IO class.
If the gzip file header is incorrect, raises an
((<Zlib::GzipFile::Error>)) exception.
--- Zlib::GzipReader.wrap(io) {|gz| ... }
Creates a GzipReader object associated with ((|io|)), and
executes the block with the newly created GzipReader object,
just like File::open. The GzipReader object will be closed
automatically after executing the block. If you want to keep
the associated IO object opening, you may call
((<Zlib::GzipFile#finish>)) method in the block.
Opens a file specified by ((|filename|)) as a gzipped file,
and returns a GzipReader object associated with that file.
Further details of this method are same as
((<Zlib::GzipReader.new>)) and ((<ZLib::GzipReader.wrap>)).
Same as IO, but raises ((<Zlib::Error>)) or
((<Zlib::GzipFile::Error>)) exception if an error was found
in the gzip file.
Be careful of the footer of gzip file. A gzip file has
the checksum of pre-compressed data in its footer.
GzipReader checks all uncompressed data against that checksum
at the following cases, and if failed, raises
((<Zlib::GzipFile::NoFooter>)), ((<Zlib::GzipFile::CRCError>)),
or ((<Zlib::GzipFile::LengthError>)) exception.
* When an reading request is received beyond the end of file
(the end of compressed data).
That is, when ((<Zlib::GzipReader#read>)),
((<Zlib::GzipReader#gets>)), or some other methods for reading
returns nil.
* When ((<Zlib::GzipFile#close>)) method is called after
the object reaches the end of file.
* When ((<Zlib::GzipReader#unused>)) method is called after
the object reaches the end of file.
--- Zlib::GzipReader#rewind
Resets the position of the file pointer to the point
created the GzipReader object.
The associated IO object need to respond to seek method.
--- Zlib::GzipReader#unused
Returns the rest of the data which had read for parsing gzip
format, or nil if the whole gzip file is not parsed yet.
== Zlib::GzipWriter
The class for writing a gzipped file. GzipWriter should be used
with associate with an instance of IO class (or an object which
has the same methods as IO has).
Zlib::GzipWriter.open('hoge.gz') {|gz|
gz.write 'jugemu jugemu gokou no surikire...'
}
f = File.open('hoge.gz', 'w')
gz = Zlib::GzipWriter.new(f)
gz.write 'jugemu jugemu gokou no surikire...'
gz.close
NOTE: Due to the limitation in finalizer of Ruby, you must close
explicitly GzipWriter object by ((<Zlib::GzipWriter#close>)) etc.
Otherwise, GzipWriter should be not able to write gzip footer and
generate broken gzip file.
=== SuperClass:
* ((<Zlib::GzipFile>))
=== Class Methods:
--- Zlib::GzipWriter.new(io[, level[, strategy]])
Creates a GzipWriter object associated with ((|io|)).
((|level|)) and ((|strategy|)) should be same as the
arguments of ((<Zlib::Deflate.new>)). The GzipWriter object
writes gzipped data to ((|io|)). At least, ((|io|)) must
respond to write method that behaves same as write method
in IO class.
Creates a GzipWriter object associated with ((|io|)), and
executes the block with the newly created GzipWriter object,
just like File::open. The GzipWriter object will be closed
automatically after executing the block. If you want to keep
the associated IO object opening, you may call
((<Zlib::GzipFile#finish>)) method in the block.
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 same as ((<Zlib::GzipWriter.new>)) and
((<Zlib::GzipWriter#wrap>)).
Closes the GzipFile object. This method calls close method
of the associated IO object. Returns the associated IO object.
See ((<Zlib::GzipFile#close>)) and ((<Zlib::GzipFile#finish>))
for the difference between close and finish.
((*NOTE: Due to the limitation in finalizer of Ruby, you must
close GzipWriter object explicitly. Otherwise, GzipWriter
should be not able to write gzip footer and generate broken
gzip file.*))
Flushes all the internal buffers of the GzipWriter object.
The meaning of ((|flush|)) is same as one of the argument of
((<Zlib::Deflate#deflate>)).
((<Zlib::SYNC_FLUSH>)) is used if ((|flush|)) is omitted.
It is no use giving ((|flush|)) ((<Zlib::NO_FLUSH>)).
--- Zlib::GzipWriter#mtime= time
Sets last modification time to be stored in the gzip file
header. ((<Zlib::GzipFile::Error>)) exception will be raised
if this method is called after writing method (like
((<Zlib::GzipWriter#write>))) was called.
--- Zlib::GzipWriter#orig_name= filename
Sets original filename to be stored in the gzip file header.
((<Zlib::GzipFile::Error>)) exception will be raised
if this method is called after writing method (like
((<Zlib::GzipWriter#write>))) was called.
--- Zlib::GzipWriter#comment= string
Sets comments to be stored in the gzip file header.
((<Zlib::GzipFile::Error>)) exception will be raised
if this method is called after writing method (like
((<Zlib::GzipWriter#write>))) was called.
* ((<Zlib::GzipFile.new>)) now takes no block. Use
((<Zlib::GzipFile.wrap>)) instead.
* ((<Zlib::GzipFile#close>)) now takes no argument. Use
((<Zlib::GzipFile#finish>)) instead.
* Renamed methods:
* Zlib.version is renamed to ((<Zlib.zlib_version>)).
* Changed constants:
* ((<Zlib::VERSION>)) indicates the version of Ruby/zlib.
The zlib.h version is now in ((<Zlib::ZLIB_VERSION>)).
* Backward compatibility:
* For backward compatibility for 0.5, the obsoleted methods and
arguments are still available.
* Obsoleted classes, methods, and constants for backward
compatibility for 0.4 or earlier are removed.
== Changes from 0.4 to 0.5
Almost all the code are rewritten.
I hope all changes are enumerated below :-)
* The names of almost classes and some methods are changed.
All classes and constants are now defined under module
((<Zlib>)). The obsoleted names are also available for backward
compatibility.
* ((<Zlib::GzipReader#unused>)) returns nil after closing.
* Now you are up to call ((<Zlib::GzipWriter#close>)) explicitly
to avoid segv in finalizer.
((<[ruby-dev:11915]|URL:http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/11915>))
* divided initialize from new.
* remove sanity checks for arguments for deflateInit2 and
inflateInit2.
* adapted the behavior of ((<Zlib::GzipWriter#puts>)) to Ruby-1.7.
Inputs ((|string|)) into the end of input buffer and
skips data until a full flush point can be found.
If the point is found in the buffer, this method flushes
the buffer and returns false. Otherwise it returns true
and the following data of full flush point is preserved
in the buffer.
Closes the GzipFile object. This method calls close method
of the associated IO object. Returns the associated IO object.
--- Zlib::GzipFile#finish
Closes the GzipFile object. Unlike ((<Zlib::GzipFile#close>)),
this method ((*never*)) calls close method of the associated IO
object. Returns the associated IO object.
--- Zlib::GzipFile#crc
Returns CRC value of the uncompressed data.
--- Zlib::GzipFile#level
Returns compression level.
--- Zlib::GzipFile#mtime
Returns last modification time recorded in the gzip
file header.
--- Zlib::GzipFile#os_code
Returns OS code number recorded in the gzip file header.
--- Zlib::GzipFile#orig_name
Returns original filename recorded in the gzip file header,
or nil if original filename is not present.
--- Zlib::GzipFile#comment
Returns comments recorded in the gzip file header, or
nil if the comments is not present.
--- Zlib::GzipFile#sync
--- Zlib::GzipFile#sync= flag
Same as IO. If ((|flag|)) is true, the associated IO object
must respond to flush method. While `sync' mode is true,
the compression ratio decreases sharply.
== Zlib::GzipFile::Error
The superclass for all exceptions raised during processing a gzip
file.
The following exceptions are defined as subclasses of
Zlib::GzipFile::Error.
: Zlib::GzipFile::NoFooter
Raised when gzip file footer has not found.
: Zlib::GzipFile::CRCError
Raised when the CRC checksum recorded in gzip file footer
is not equivalent to CRC checksum of the actually
uncompressed data.
: Zlib::GzipFile::LengthError
Raised when the data length recorded in gzip file footer
is not equivalent to length of the actually uncompressed data.
=== 超级类:
* ((<Zlib::Error>))
== Zlib::GzipReader
The class for reading a gzipped file. GzipReader should be used
with associating an instance of IO class (or an object which has
the same methods as IO has).
f = File.open('hoge.gz')
gz = Zlib::GzipReader.new(f)
print gz.read
gz.close
=== 超级类:
* ((<Zlib::GzipFile>))
=== 包含的模块:
* Enumerable
=== Class Methods:
--- Zlib::GzipReader.new(io)
Creates a GzipReader object associated with ((|io|)).
The GzipReader object reads gzipped data from ((|io|)),
and parses/decompresses them. At least, ((|io|)) must have
read method that behaves same as read method in IO class.
If the gzip file header is incorrect, raises an
((<Zlib::GzipFile::Error>)) exception.
--- Zlib::GzipReader.wrap(io) {|gz| ... }
Creates a GzipReader object associated with ((|io|)), and
executes the block with the newly created GzipReader object,
just like File::open. The GzipReader object will be closed
automatically after executing the block. If you want to keep
the associated IO object opening, you may call
((<Zlib::GzipFile#finish>)) method in the block.
Opens a file specified by ((|filename|)) as a gzipped file,
and returns a GzipReader object associated with that file.
Further details of this method are same as
((<Zlib::GzipReader.new>)) and ((<ZLib::GzipReader.wrap>)).
Same as IO, but raises ((<Zlib::Error>)) or
((<Zlib::GzipFile::Error>)) exception if an error was found
in the gzip file.
Be careful of the footer of gzip file. A gzip file has
the checksum of pre-compressed data in its footer.
GzipReader checks all uncompressed data against that checksum
at the following cases, and if failed, raises
((<Zlib::GzipFile::NoFooter>)), ((<Zlib::GzipFile::CRCError>)),
or ((<Zlib::GzipFile::LengthError>)) exception.
* When an reading request is received beyond the end of file
(the end of compressed data).
That is, when ((<Zlib::GzipReader#read>)),
((<Zlib::GzipReader#gets>)), or some other methods for reading
returns nil.
* When ((<Zlib::GzipFile#close>)) method is called after
the object reaches the end of file.
* When ((<Zlib::GzipReader#unused>)) method is called after
the object reaches the end of file.
--- Zlib::GzipReader#rewind
Resets the position of the file pointer to the point
created the GzipReader object.
The associated IO object need to respond to seek method.
--- Zlib::GzipReader#unused
Returns the rest of the data which had read for parsing gzip
format, or nil if the whole gzip file is not parsed yet.
== Zlib::GzipWriter
The class for writing a gzipped file. GzipWriter should be used
with associate with an instance of IO class (or an object which
has the same methods as IO has).
Zlib::GzipWriter.open('hoge.gz') {|gz|
gz.write 'jugemu jugemu gokou no surikire...'
}
f = File.open('hoge.gz', 'w')
gz = Zlib::GzipWriter.new(f)
gz.write 'jugemu jugemu gokou no surikire...'
gz.close
NOTE: Due to the limitation in finalizer of Ruby, you must close
explicitly GzipWriter object by ((<Zlib::GzipWriter#close>)) etc.
Otherwise, GzipWriter should be not able to write gzip footer and
generate broken gzip file.
=== SuperClass:
* ((<Zlib::GzipFile>))
=== Class Methods:
--- Zlib::GzipWriter.new(io[, level[, strategy]])
Creates a GzipWriter object associated with ((|io|)).
((|level|)) and ((|strategy|)) should be same as the
arguments of ((<Zlib::Deflate.new>)). The GzipWriter object
writes gzipped data to ((|io|)). At least, ((|io|)) must
respond to write method that behaves same as write method
in IO class.
Creates a GzipWriter object associated with ((|io|)), and
executes the block with the newly created GzipWriter object,
just like File::open. The GzipWriter object will be closed
automatically after executing the block. If you want to keep
the associated IO object opening, you may call
((<Zlib::GzipFile#finish>)) method in the block.
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 same as ((<Zlib::GzipWriter.new>)) and
((<Zlib::GzipWriter#wrap>)).
Closes the GzipFile object. This method calls close method
of the associated IO object. Returns the associated IO object.
See ((<Zlib::GzipFile#close>)) and ((<Zlib::GzipFile#finish>))
for the difference between close and finish.
((*NOTE: Due to the limitation in finalizer of Ruby, you must
close GzipWriter object explicitly. Otherwise, GzipWriter
should be not able to write gzip footer and generate broken
gzip file.*))
Flushes all the internal buffers of the GzipWriter object.
The meaning of ((|flush|)) is same as one of the argument of
((<Zlib::Deflate#deflate>)).
((<Zlib::SYNC_FLUSH>)) is used if ((|flush|)) is omitted.
It is no use giving ((|flush|)) ((<Zlib::NO_FLUSH>)).
--- Zlib::GzipWriter#mtime= time
Sets last modification time to be stored in the gzip file
header. ((<Zlib::GzipFile::Error>)) exception will be raised
if this method is called after writing method (like
((<Zlib::GzipWriter#write>))) was called.
--- Zlib::GzipWriter#orig_name= filename
Sets original filename to be stored in the gzip file header.
((<Zlib::GzipFile::Error>)) exception will be raised
if this method is called after writing method (like
((<Zlib::GzipWriter#write>))) was called.
--- Zlib::GzipWriter#comment= string
Sets comments to be stored in the gzip file header.
((<Zlib::GzipFile::Error>)) exception will be raised
if this method is called after writing method (like
((<Zlib::GzipWriter#write>))) was called.
* ((<Zlib::GzipFile.new>)) now takes no block. Use
((<Zlib::GzipFile.wrap>)) instead.
* ((<Zlib::GzipFile#close>)) now takes no argument. Use
((<Zlib::GzipFile#finish>)) instead.
* Renamed methods:
* Zlib.version is renamed to ((<Zlib.zlib_version>)).
* Changed constants:
* ((<Zlib::VERSION>)) indicates the version of Ruby/zlib.
The zlib.h version is now in ((<Zlib::ZLIB_VERSION>)).
* Backward compatibility:
* For backward compatibility for 0.5, the obsoleted methods and
arguments are still available.
* Obsoleted classes, methods, and constants for backward
compatibility for 0.4 or earlier are removed.
== Changes from 0.4 to 0.5
Almost all the code are rewritten.
I hope all changes are enumerated below :-)
* The names of almost classes and some methods are changed.
All classes and constants are now defined under module
((<Zlib>)). The obsoleted names are also available for backward
compatibility.
* ((<Zlib::GzipReader#unused>)) returns nil after closing.
* Now you are up to call ((<Zlib::GzipWriter#close>)) explicitly
to avoid segv in finalizer.
((<[ruby-dev:11915]|URL:http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/11915>))
* divided initialize from new.
* remove sanity checks for arguments for deflateInit2 and
inflateInit2.
* adapted the behavior of ((<Zlib::GzipWriter#puts>)) to Ruby-1.7.