设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 5382|回复: 10
打印 上一主题 下一主题

[RM脚本] Zlib 不完整翻译

 关闭 [复制链接]

Lv1.梦旅人

逃兵

跳转到指定楼层
1
发表于 2007-2-22 05:07:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
有错请原谅...{/tp}


=begin
#
# zlib.rd.src
#
#   Copyright (C) UENO Katsuhiro 2000-2003
#
# $Id: zlib.rd,v 1.2 2004/03/28 14:10:39 akr Exp $
#

= Ruby/zlib 版本 0.6.0

Ruby/zlib是一个为在Ruby中使用zlib的扩展的库。
Ruby/zlib同样提供访问gzip文件的功能。

你可以按照Ruby解释器的格式更改或重新定义Ruby/zlib,
Ruby/zlib最新的版本可以在http://www.blue.sky.or.jp/上找到。

我们欢迎所有的注释和建议,请把它们发到ruby-list ML、ruby-ext ML、
ruby-talk ML,或者发到创作者的邮箱中([email protected])。

这个文件是根据实验和英文版本编写的。如果你在这个文件中发现了错误或
奇怪的公式(including kidding or unnatural ones),请告诉我以助于我的学习。



目录:

* ((<Zlib>))

  * ((<Zlib::Error>))
  * ((<Zlib::ZStream>))
  * ((<Zlib::Deflate>))
  * ((<Zlib::Inflate>))
  * ((<Zlib::GzipFile>))
  * ((<Zlib::GzipFile::Error>))
  * ((<Zlib::GzipWriter>))
  * ((<Zlib::GzipReader>))

* ((<Changes from 0.5 to 0.6>))
* ((<Changes from 0.4 to 0.5>))




== Zlib

Zlib是一个提过zlib在c语言库里的模块。
请到zlib.h中寻找对各个功能更详细的介绍。

=== 模块功能:

--- Zlib.zlib_version

    返回表示zlib库版本的字符串

--- Zlib.adler32([string[, adler]])

    对string进行计算Alder-32检查,并返回alder的最新的值。
    如果string缺省,则返回Adler-32的初始值,
    如果alder缺省,将认为初始值已经被赋予alder。

--- Zlib.crc32([string[, crc]])

    对string进行计算CRC检查,并返回crc的最新的值。
    如果string缺省,则返回CRC的初始值,
    如果crc缺省,将认为初始值已经被赋予crc。

--- Zlib.crc_table

    返回计算CRC检查用的平台(数组型)。

=== 常量:

--- Zlib::VERSION

    Ruby/zlib版本(字符串)。

--- Zlib::ZLIB_VERSION

    提供zlib.h版本的字符串。

--- Zlib::BINARY
--- Zlib::ASCII
--- Zlib::UNKNOWN

    描绘数据类型的整数(Zlib::ZStream#data_type的参数)。

--- Zlib::NO_COMPRESSION
--- Zlib::BEST_SPEED
--- Zlib::BEST_COMPRESSION
--- Zlib::DEFAULT_COMPRESSION

    描绘压缩级别的整数(Zlib::Deflate.new和Zlib::Deflate#deflate的参数)。

--- Zlib::FILTERED
--- Zlib::HUFFMAN_ONLY
--- Zlib::DEFAULT_STRATEGY

    描绘压缩方法的整数(Zlib::Deflate.new和Zlib::Deflate#params的参数)。

--- Zlib::DEF_MEM_LEVEL
--- Zlib::MAX_MEM_LEVEL

    描绘记忆级别的整数(Zlib::Deflate.new、Zlib::Deflate#params及其他方法的参数)

--- Zlib::MAX_WBITS

    windowBits的缺省值(Zlib::Deflate.new和Zlib::Inflate.new的参数)。

--- Zlib::NO_FLUSH
--- Zlib::SYNC_FLUSH
--- Zlib::FULL_FLUSH
--- Zlib::FINISH

    控制输出的流的整数(Zlib::Deflate#deflate及其他方法的参数)。

--- Zlib::OS_CODE
--- Zlib::OS_MSDOS
--- Zlib::OS_AMIGA
--- Zlib::OS_VMS
--- Zlib::OS_UNIX
--- Zlib::OS_VMCMS
--- Zlib::OS_ATARI
--- Zlib::OS_OS2
--- Zlib::OS_MACOS
--- Zlib::OS_ZSYSTEM
--- Zlib::OS_CPM
--- Zlib::OS_TOPS20
--- Zlib::OS_WIN32
--- Zlib::OS_QDOS
--- Zlib::OS_RISCOS
--- Zlib::OS_UNKNOWN

    返回Zlib::GzipFile#os_code方法的值。

== Zlib::Error

在Ruby/zlib中所有异常类的超级类

下列异常类在Zlib::Error中被定义,
这些异常类将在zlib库的方法在错误的情况下被返回时调用。

  * Zlib::StreamEnd
  * Zlib::NeedDict
  * Zlib::DataError
  * Zlib::StreamError
  * Zlib::MemError
  * Zlib::BufError
  * Zlib::VersionError

=== 超级类:

* StandardError

== Zlib::ZStream

为“流”设定的抽象类,用于处理被压缩的资料。
其操作被定义在其子类中(在Zlib::Deflate中压缩,
在Zlib::Inflate中解压缩)

一个Zlib::ZStream的实例有一个流(struct zstream)和两个可变大小的
缓冲器(集合了向流中输入(next_in)和输出(next_out)两种方法)。
在这个文档中, "input buffer"代表输入数据用的缓冲器,
"output buffer" 代表输入用的缓冲器。

数据被输入进Zlib::ZStream的一个实例实际上是短暂地输入input buffer的
最后,然后,在input buffer中的数据被处理(从缓冲器的开头开始,直到流
中再没有可被输出的数据)。
在处理期间, output buffer被扩大并自动保留所有要输出的数据。

一些详细的实例方法将清除在output buffer中的数据,并将它们输出为一个
字符串。

这是一个上述内容的图表:

     +================   一个Zlib::ZStream的实例    ================+
     ||                                                            ||
     ||     +--------+          +-------+          +--------+      ||
     ||  +--| 输出解 |<---------|zstream|<---------| 输入解 |<--+  ||
     ||  |  |  释器  |  next_out+-------+next_in   |  释器  |   |  ||
     ||  |  +--------+                             +--------+   |  ||
     ||  |                                                      |  ||
     +===|======================================================|===+
         |                                                      |
         v                                                      |
     输出的数据                                             输入的数据

如果在输入期间发生异常,一个作为Zlib::Error子类的异常类将被调用。
此时两个缓冲器保持各自在错误发生时的状态。

=== 超级类:

* Object

=== 类方法

--- Zlib::ZStream.new

    参考Zlib::Deflate.newZlib::Inflate.new。

=== 方法:

--- Zlib::ZStream#avail_in

    返回在input buffer中数据的字节数,
    通常地,返回0。

--- Zlib::ZStream#avail_out

    返回output buffer的空闲空间的字节数。
    因为空闲空间是被自动分配的,
    所以这个方法通常返回0。

--- Zlib::ZStream#avail_out = size

    分配给输出解释器size字节的空闲空间,
    如果在解释器中有比size字节更多的空闲空间,
    解释器将被删节。
    因为空闲空间是自动分配的,你通常不用调用这个方法。

--- Zlib::ZStream#flush_next_in

    清空input buffer并返回其中的所有数据。

--- Zlib::ZStream#flush_next_out

    清空output buffer并返回其中的所有数据。

--- Zlib::ZStream#total_in

    返回输入流的数据总字节数。

--- Zlib::ZStream#total_out

    返回从流输出的数据总字节数。

--- Zlib::ZStream#data_type

    猜测输入流的数据的类型,其结果将是Zlib::BINARY、
    Zlib::ASCII或Zlib::UNKNOWN中的一个

--- Zlib::ZStream#adler

    返回alder-32检查。

--- Zlib::ZStream#reset

    重新设定并初始化流,在两个解释器中的所有数据将被抛弃。

--- Zlib::ZStream#finish

    完成流并清空output buffer。
    详细的行为说明请参考Zlib::Deflate#finish和Zlib::Inflate#finish。

--- Zlib::ZStream#finished?
--- Zlib::ZStream#stream_end?

    如果流已经完成将返回true

--- Zlib::ZStream#close
--- Zlib::ZStream#end

    关闭流。所有在已经关闭的流上的操作将引发异常。

--- Zlib::ZStream#closed?
--- Zlib::ZStream#ended?

    如果流已经关闭将返回true


== Zlib::Deflate

用于压缩字符串数据的类。

=== 超级类:

* ((<Zlib::ZStream>))

=== 类方法:

--- Zlib::Deflate.deflate(string[, level])

    压缩string。有效的level值是Zlib::NO_COMPRESSION、
    Zlib::BEST_SPEED、Zlib::BEST_COMPRESSION、
    Zlib::DEFAULT_COMPRESSION和0-9的整数。

    这个方法通常等同于下列代码:

      def deflate(string, level)
        z = Zlib::Deflate.new(level)
        dst = z.deflate(string, Zlib::FINISH)
        z.close
        dst
      end

--- Zlib::Deflate.new([level[, windowBits[, memlevel[, strategy]]]])

    新建一个新的deflate流用于压缩。
    各参数详细信息请参考zlib.h。
    如果有一个参数是nil,默认值将是这个参数从前使用过的值

=== 方法:

--- Zlib::Deflate#clone

    复制这个deflate流。

--- Zlib::Deflate#deflate(string[, flush])

    输入string进入这个deflate流,并返回这个流的输出值。
    调用这个方法将同时清空这个流的两个缓冲器。
    如果string是nil,这个方法将结束这个流,就像Zlib::ZStream#finish。
    flush参数的值必须是Zlib::NO_FLUSH、Zlib::SYNC_FLUSH、
    Zlib::FULL_FLUSH或Zlib::FINISH中的一个。
    详细信息请参考zlib.h。

--- Zlib::Deflate#<< string

    输入string进入这个deflate流,就像Zlib::Deflate#deflate,
    但返回这个流本身。
    输出值将被保留在output buffer中

--- Zlib::Deflate#flush([flush])

    这个方法等同于Zlib::Deflate#deflate('', flush)。
    如果flush被省略,将把Zlib::SYNC_FLUSH作为flush的值
    这个方法只是为了使你的Ruby脚本更易读懂

--- Zlib::Deflate#finish

    结束这个流。
    这个方法等同于Zlib::Deflate#deflate('', Zlib::FINISH)。

--- Zlib::Deflate#params(level, strategy)

    改变这个deflate的参数。
    详细信息请参考zlib.h。
    这个流被参数修改的输出值将被保存在output buffer中。

--- Zlib::Deflate#set_dictionary(string)

    Sets the preset dictionary(不会翻……)并返回string。
    这个方法只有在Zlib::Deflate.new或Zlib::ZStream#reset被调用后可用。
    详细信息请参考zlib.h。


== Zlib::Inflate

这个类用于解压压缩的数据。
不象Zlib::Deflate这个类的实例不能复制(clone, dup)其本身。

=== 超级类:

* ((<Zlib::ZStream>))

=== 类方法:

--- Zlib::Inflate.inflate(string)

    解压缩string。
    如果因为缺少解压所必须的preset dictionary而出现异常,
    则调用Zlib::NeedDict。

    这个方法等同于下列代码:

      def inflate(string)
        zstream = Zlib::Inflate.new
        buf = zstream.inflate(string)
        zstream.finish
        zstream.close
        buf
      end

--- Zlib::Inflate.new([windowBits])

    新建一个新的用于解压的inflate流。
    参数的详细信息请参考zlib.h。
    如果有windowBits是nil,默认值将是这个参数从前使用过的值。

=== 方法:

--- Zlib::Inflate#inflate(string)

    输入string进入这个inflate流,并返回这个流的输出值。
    调用这个方法将同时清空这个流的两个缓冲器。
    如果string是nil,这个方法将结束这个流,就像Zlib::ZStream#finish。

    如果因为缺少解压所必须的preset dictionary而出现异常,
    则调用Zlib::NeedDict。
    可使用Zlib::Inflate#set_dictionary并且用一个空的字符串
    再次调用这个方法来设定preset dictionary

--- Zlib::Inflate#<< string

    输入string进入这个inflate流,就像Zlib::Inflate#inflate,
    但返回这个流本身。输出值将被保留在output buffer中

--- Zlib::Inflate#finish

    结束这个inflate流并且返回被压缩数据的garbage。
    如果这个流没有结束将引发异常。
    (i.e. ((<Zlib::ZStream#finished?>)) doesn't returns true).

    inflate流将在它处理完最后一个被压缩数据时结束其本身,
    所以你并不需要明确地调用这个方法。然而,这个方法有益于检查
    数据是否正常地结束。

--- Zlib::Inflate#set_dictionary(string)

    设置preset dictionary并返回string。
    这个方法只要在出现Zlib::NeedDict意外之后才有用。
    详细信息请参考zlib.h。

--- Zlib::Inflate#sync(string)

    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.

    没明白作用……

--- Zlib::Inflate#sync_point?

    What is this?


== Zlib::GzipFile

用于处理gzip格式压缩文件的抽象的类。
其操作被定义在其子类中,
Zlib::GzipReader读取,Zlib::GzipWriter写入。

GzipReader should be used with associating an instance of IO class
(or an object which has the same methods as IO has).

=== SuperClass:

* Object

=== Class Methods:

--- Zlib::GzipFile.new(args...)

    See ((<Zlib::GzipReader.new>)) and ((<Zlib::GzipWriter.new>)).

--- Zlib::GzipFile.wrap(args...) {|gz| ... }

    See ((<Zlib::GzipReader.wrap>)) and ((<Zlib::GzipWriter.wrap>)).

--- Zlib::GzipFile.open(args...) {|gz| ... }

    See ((<Zlib::GzipReader.open>)) and ((<Zlib::GzipWriter.open>)).

=== Methods:

--- Zlib::GzipFile#closed?
--- Zlib::GzipFile#to_io

    Same as IO.

--- Zlib::GzipFile#close

    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).

    Zlib::GzipReader.open('hoge.gz') {|gz|
      print gz.read
    }

    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.

--- Zlib::GzipReader.open(filename)
--- Zlib::GzipReader.open(filename) {|gz| ... }

    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>)).

=== メソッド:

--- Zlib::GzipReader#eof
--- Zlib::GzipReader#eof?

    Returns true if the object reaches the end of compressed data.
    Note that eof? does ((*not*)) return true when reaches the
    end of ((*file*)).

--- Zlib::GzipReader#pos
--- Zlib::GzipReader#tell

    Returns the total bytes of data decompressed until now.
    Not that it does ((*not*)) the position of file pointer.

--- Zlib::GzipReader#each([rs])
--- Zlib::GzipReader#each_line([rs])
--- Zlib::GzipReader#each_byte([rs])
--- Zlib::GzipReader#gets([rs])
--- Zlib::GzipReader#getc
--- Zlib::GzipReader#lineno
--- Zlib::GzipReader#lineno=
--- Zlib::GzipReader#read([length])
--- Zlib::GzipReader#readchar
--- Zlib::GzipReader#readline([rs])
--- Zlib::GzipReader#readlines([rs])
--- Zlib::GzipReader#ungetc(char)

    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.

--- Zlib::GzipWriter.wrap(io[, level[, strategy]]) {|gz| ... }

    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.

--- Zlib::GzipWriter.open(filename[, level[, strategy]])
--- Zlib::GzipWriter.open(filename[, level[, strategy]]) {|gz| ... }

    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>)).


=== Methods:

--- Zlib::GzipWriter#close
--- Zlib::GzipWriter#finish

    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.*))

--- Zlib::GzipWriter#pos
--- Zlib::GzipWriter#tell

    Returns the total bytes of data compressed until now.
    Note that it does ((*not*)) the position of file pointer.

--- Zlib::GzipWriter#<< str
--- Zlib::GzipWriter#putc(ch)
--- Zlib::GzipWriter#puts(obj...)
--- Zlib::GzipWriter#print(arg...)
--- Zlib::GzipWriter#printf(format, arg...)
--- Zlib::GzipWriter#write(str)

    Same as IO.

--- Zlib::GzipWriter#flush([flush])

    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.


== Changes from 0.5 to 0.6

* New methods:

  * ((<Zlib::GzipFile.wrap>))
  * ((<Zlib::GzipFile#finish>))

* New constants:

  * ((<Zlib::ZLIB_VERSION>))
  * ((<Zlib::OS_VMCMS>))
  * ((<Zlib::OS_ZSYSTEM>))
  * ((<Zlib::OS_CPM>))
  * ((<Zlib::OS_QDOS>))
  * ((<Zlib::OS_RISCOS>))
  * ((<Zlib::OS_UNKNOWN>))

* Changed methods:

  * ((<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.

  * Classes

    * Deflate -> ((<Zlib::Deflate>))
    * Inflate -> ((<Zlib::Inflate>))
    * Zlib::Gzip -> ((<Zlib::GzipFile>))
    * GzipReader -> ((<Zlib::GzipReader>))
    * GzipWriter -> ((<Zlib::GzipWriter>))
    * Zlib::Gzip::Error -> ((<Zlib::GzipFile::Error>))
    * Zlib::GzipReader::NoFooter -> ((<Zlib::GzipFile::NoFooter>))
    * Zlib::GzipReader::CRCError -> ((<Zlib::GzipFile::CRCError>))
    * Zlib::GzipReader::LengthError -> ((<Zlib::GzipFile::LengthError>))

  * Constants

    * Zlib::ZStream::BINARY -> ((<Zlib::BINARY>))
    * Zlib::ZStream::ASCII -> ((<Zlib::ASCII>))
    * Zlib::ZStream::UNKNOWN -> ((<Zlib::UNKNOWN>))
    * Zlib::Deflate::NO_COMPRESSION -> ((<Zlib::NO_COMPRESSION>))
    * Zlib::Deflate::BEST_SPEED -> ((<Zlib::BEST_SPEED>))
    * Zlib::Deflate::BEST_COMPRESSION -> ((<Zlib::BEST_COMPRESSION>))
    * Zlib::Deflate::DEFAULT_COMPRESSION -> ((<Zlib::DEFAULT_COMPRESSION>))
    * Zlib::Deflate::FILTERED -> ((<Zlib::FILTERED>))
    * Zlib::Deflate::HUFFMAN_ONLY -> ((<Zlib::HUFFMAN_ONLY>))
    * Zlib::Deflate::DEFAULT_STRATEGY -> ((<Zlib::DEFAULT_STRATEGY>))
    * Zlib::Deflate::MAX_WBITS -> ((<Zlib::MAX_WBITS>))
    * Zlib::Deflate::DEF_MEM_LEVEL -> ((<Zlib::DEF_MEM_LEVEL>))
    * Zlib::Deflate::MAX_MEM_LEVEL -> ((<Zlib::MAX_MEM_LEVEL>))
    * Zlib::Deflate::NO_FLUSH -> ((<Zlib::NO_FLUSH>))
    * Zlib::Deflate::SYNC_FLUSH -> ((<Zlib::SYNC_FLUSH>))
    * Zlib::Deflate::FULL_FLUSH -> ((<Zlib::FULL_FLUSH>))
    * Zlib::Inflate::MAX_WBITS -> ((<Zlib::MAX_WBITS>))
    * Zlib::GzipReader::OS_* -> ((<Zlib::OS_*|Zlib::OS_CODE>))

  * Methods

    * Zlib::ZStream#flush_out -> ((<Zlib::ZStream#flush_next_out>))

* Made buffer for input (next_in).

* ((<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.

* Made all functions static.


=end
「If you judge people, you have no time to love them.」—— Mother Teresa

Lv1.梦旅人

逃兵

2
 楼主| 发表于 2007-2-22 05:07:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
有错请原谅...{/tp}


=begin
#
# zlib.rd.src
#
#   Copyright (C) UENO Katsuhiro 2000-2003
#
# $Id: zlib.rd,v 1.2 2004/03/28 14:10:39 akr Exp $
#

= Ruby/zlib 版本 0.6.0

Ruby/zlib是一个为在Ruby中使用zlib的扩展的库。
Ruby/zlib同样提供访问gzip文件的功能。

你可以按照Ruby解释器的格式更改或重新定义Ruby/zlib,
Ruby/zlib最新的版本可以在http://www.blue.sky.or.jp/上找到。

我们欢迎所有的注释和建议,请把它们发到ruby-list ML、ruby-ext ML、
ruby-talk ML,或者发到创作者的邮箱中([email protected])。

这个文件是根据实验和英文版本编写的。如果你在这个文件中发现了错误或
奇怪的公式(including kidding or unnatural ones),请告诉我以助于我的学习。



目录:

* ((<Zlib>))

  * ((<Zlib::Error>))
  * ((<Zlib::ZStream>))
  * ((<Zlib::Deflate>))
  * ((<Zlib::Inflate>))
  * ((<Zlib::GzipFile>))
  * ((<Zlib::GzipFile::Error>))
  * ((<Zlib::GzipWriter>))
  * ((<Zlib::GzipReader>))

* ((<Changes from 0.5 to 0.6>))
* ((<Changes from 0.4 to 0.5>))




== Zlib

Zlib是一个提过zlib在c语言库里的模块。
请到zlib.h中寻找对各个功能更详细的介绍。

=== 模块功能:

--- Zlib.zlib_version

    返回表示zlib库版本的字符串

--- Zlib.adler32([string[, adler]])

    对string进行计算Alder-32检查,并返回alder的最新的值。
    如果string缺省,则返回Adler-32的初始值,
    如果alder缺省,将认为初始值已经被赋予alder。

--- Zlib.crc32([string[, crc]])

    对string进行计算CRC检查,并返回crc的最新的值。
    如果string缺省,则返回CRC的初始值,
    如果crc缺省,将认为初始值已经被赋予crc。

--- Zlib.crc_table

    返回计算CRC检查用的平台(数组型)。

=== 常量:

--- Zlib::VERSION

    Ruby/zlib版本(字符串)。

--- Zlib::ZLIB_VERSION

    提供zlib.h版本的字符串。

--- Zlib::BINARY
--- Zlib::ASCII
--- Zlib::UNKNOWN

    描绘数据类型的整数(Zlib::ZStream#data_type的参数)。

--- Zlib::NO_COMPRESSION
--- Zlib::BEST_SPEED
--- Zlib::BEST_COMPRESSION
--- Zlib::DEFAULT_COMPRESSION

    描绘压缩级别的整数(Zlib::Deflate.new和Zlib::Deflate#deflate的参数)。

--- Zlib::FILTERED
--- Zlib::HUFFMAN_ONLY
--- Zlib::DEFAULT_STRATEGY

    描绘压缩方法的整数(Zlib::Deflate.new和Zlib::Deflate#params的参数)。

--- Zlib::DEF_MEM_LEVEL
--- Zlib::MAX_MEM_LEVEL

    描绘记忆级别的整数(Zlib::Deflate.new、Zlib::Deflate#params及其他方法的参数)

--- Zlib::MAX_WBITS

    windowBits的缺省值(Zlib::Deflate.new和Zlib::Inflate.new的参数)。

--- Zlib::NO_FLUSH
--- Zlib::SYNC_FLUSH
--- Zlib::FULL_FLUSH
--- Zlib::FINISH

    控制输出的流的整数(Zlib::Deflate#deflate及其他方法的参数)。

--- Zlib::OS_CODE
--- Zlib::OS_MSDOS
--- Zlib::OS_AMIGA
--- Zlib::OS_VMS
--- Zlib::OS_UNIX
--- Zlib::OS_VMCMS
--- Zlib::OS_ATARI
--- Zlib::OS_OS2
--- Zlib::OS_MACOS
--- Zlib::OS_ZSYSTEM
--- Zlib::OS_CPM
--- Zlib::OS_TOPS20
--- Zlib::OS_WIN32
--- Zlib::OS_QDOS
--- Zlib::OS_RISCOS
--- Zlib::OS_UNKNOWN

    返回Zlib::GzipFile#os_code方法的值。

== Zlib::Error

在Ruby/zlib中所有异常类的超级类

下列异常类在Zlib::Error中被定义,
这些异常类将在zlib库的方法在错误的情况下被返回时调用。

  * Zlib::StreamEnd
  * Zlib::NeedDict
  * Zlib::DataError
  * Zlib::StreamError
  * Zlib::MemError
  * Zlib::BufError
  * Zlib::VersionError

=== 超级类:

* StandardError

== Zlib::ZStream

为“流”设定的抽象类,用于处理被压缩的资料。
其操作被定义在其子类中(在Zlib::Deflate中压缩,
在Zlib::Inflate中解压缩)

一个Zlib::ZStream的实例有一个流(struct zstream)和两个可变大小的
缓冲器(集合了向流中输入(next_in)和输出(next_out)两种方法)。
在这个文档中, "input buffer"代表输入数据用的缓冲器,
"output buffer" 代表输入用的缓冲器。

数据被输入进Zlib::ZStream的一个实例实际上是短暂地输入input buffer的
最后,然后,在input buffer中的数据被处理(从缓冲器的开头开始,直到流
中再没有可被输出的数据)。
在处理期间, output buffer被扩大并自动保留所有要输出的数据。

一些详细的实例方法将清除在output buffer中的数据,并将它们输出为一个
字符串。

这是一个上述内容的图表:

     +================   一个Zlib::ZStream的实例    ================+
     ||                                                            ||
     ||     +--------+          +-------+          +--------+      ||
     ||  +--| 输出解 |<---------|zstream|<---------| 输入解 |<--+  ||
     ||  |  |  释器  |  next_out+-------+next_in   |  释器  |   |  ||
     ||  |  +--------+                             +--------+   |  ||
     ||  |                                                      |  ||
     +===|======================================================|===+
         |                                                      |
         v                                                      |
     输出的数据                                             输入的数据

如果在输入期间发生异常,一个作为Zlib::Error子类的异常类将被调用。
此时两个缓冲器保持各自在错误发生时的状态。

=== 超级类:

* Object

=== 类方法

--- Zlib::ZStream.new

    参考Zlib::Deflate.newZlib::Inflate.new。

=== 方法:

--- Zlib::ZStream#avail_in

    返回在input buffer中数据的字节数,
    通常地,返回0。

--- Zlib::ZStream#avail_out

    返回output buffer的空闲空间的字节数。
    因为空闲空间是被自动分配的,
    所以这个方法通常返回0。

--- Zlib::ZStream#avail_out = size

    分配给输出解释器size字节的空闲空间,
    如果在解释器中有比size字节更多的空闲空间,
    解释器将被删节。
    因为空闲空间是自动分配的,你通常不用调用这个方法。

--- Zlib::ZStream#flush_next_in

    清空input buffer并返回其中的所有数据。

--- Zlib::ZStream#flush_next_out

    清空output buffer并返回其中的所有数据。

--- Zlib::ZStream#total_in

    返回输入流的数据总字节数。

--- Zlib::ZStream#total_out

    返回从流输出的数据总字节数。

--- Zlib::ZStream#data_type

    猜测输入流的数据的类型,其结果将是Zlib::BINARY、
    Zlib::ASCII或Zlib::UNKNOWN中的一个

--- Zlib::ZStream#adler

    返回alder-32检查。

--- Zlib::ZStream#reset

    重新设定并初始化流,在两个解释器中的所有数据将被抛弃。

--- Zlib::ZStream#finish

    完成流并清空output buffer。
    详细的行为说明请参考Zlib::Deflate#finish和Zlib::Inflate#finish。

--- Zlib::ZStream#finished?
--- Zlib::ZStream#stream_end?

    如果流已经完成将返回true

--- Zlib::ZStream#close
--- Zlib::ZStream#end

    关闭流。所有在已经关闭的流上的操作将引发异常。

--- Zlib::ZStream#closed?
--- Zlib::ZStream#ended?

    如果流已经关闭将返回true


== Zlib::Deflate

用于压缩字符串数据的类。

=== 超级类:

* ((<Zlib::ZStream>))

=== 类方法:

--- Zlib::Deflate.deflate(string[, level])

    压缩string。有效的level值是Zlib::NO_COMPRESSION、
    Zlib::BEST_SPEED、Zlib::BEST_COMPRESSION、
    Zlib::DEFAULT_COMPRESSION和0-9的整数。

    这个方法通常等同于下列代码:

      def deflate(string, level)
        z = Zlib::Deflate.new(level)
        dst = z.deflate(string, Zlib::FINISH)
        z.close
        dst
      end

--- Zlib::Deflate.new([level[, windowBits[, memlevel[, strategy]]]])

    新建一个新的deflate流用于压缩。
    各参数详细信息请参考zlib.h。
    如果有一个参数是nil,默认值将是这个参数从前使用过的值

=== 方法:

--- Zlib::Deflate#clone

    复制这个deflate流。

--- Zlib::Deflate#deflate(string[, flush])

    输入string进入这个deflate流,并返回这个流的输出值。
    调用这个方法将同时清空这个流的两个缓冲器。
    如果string是nil,这个方法将结束这个流,就像Zlib::ZStream#finish。
    flush参数的值必须是Zlib::NO_FLUSH、Zlib::SYNC_FLUSH、
    Zlib::FULL_FLUSH或Zlib::FINISH中的一个。
    详细信息请参考zlib.h。

--- Zlib::Deflate#<< string

    输入string进入这个deflate流,就像Zlib::Deflate#deflate,
    但返回这个流本身。
    输出值将被保留在output buffer中

--- Zlib::Deflate#flush([flush])

    这个方法等同于Zlib::Deflate#deflate('', flush)。
    如果flush被省略,将把Zlib::SYNC_FLUSH作为flush的值
    这个方法只是为了使你的Ruby脚本更易读懂

--- Zlib::Deflate#finish

    结束这个流。
    这个方法等同于Zlib::Deflate#deflate('', Zlib::FINISH)。

--- Zlib::Deflate#params(level, strategy)

    改变这个deflate的参数。
    详细信息请参考zlib.h。
    这个流被参数修改的输出值将被保存在output buffer中。

--- Zlib::Deflate#set_dictionary(string)

    Sets the preset dictionary(不会翻……)并返回string。
    这个方法只有在Zlib::Deflate.new或Zlib::ZStream#reset被调用后可用。
    详细信息请参考zlib.h。


== Zlib::Inflate

这个类用于解压压缩的数据。
不象Zlib::Deflate这个类的实例不能复制(clone, dup)其本身。

=== 超级类:

* ((<Zlib::ZStream>))

=== 类方法:

--- Zlib::Inflate.inflate(string)

    解压缩string。
    如果因为缺少解压所必须的preset dictionary而出现异常,
    则调用Zlib::NeedDict。

    这个方法等同于下列代码:

      def inflate(string)
        zstream = Zlib::Inflate.new
        buf = zstream.inflate(string)
        zstream.finish
        zstream.close
        buf
      end

--- Zlib::Inflate.new([windowBits])

    新建一个新的用于解压的inflate流。
    参数的详细信息请参考zlib.h。
    如果有windowBits是nil,默认值将是这个参数从前使用过的值。

=== 方法:

--- Zlib::Inflate#inflate(string)

    输入string进入这个inflate流,并返回这个流的输出值。
    调用这个方法将同时清空这个流的两个缓冲器。
    如果string是nil,这个方法将结束这个流,就像Zlib::ZStream#finish。

    如果因为缺少解压所必须的preset dictionary而出现异常,
    则调用Zlib::NeedDict。
    可使用Zlib::Inflate#set_dictionary并且用一个空的字符串
    再次调用这个方法来设定preset dictionary

--- Zlib::Inflate#<< string

    输入string进入这个inflate流,就像Zlib::Inflate#inflate,
    但返回这个流本身。输出值将被保留在output buffer中

--- Zlib::Inflate#finish

    结束这个inflate流并且返回被压缩数据的garbage。
    如果这个流没有结束将引发异常。
    (i.e. ((<Zlib::ZStream#finished?>)) doesn't returns true).

    inflate流将在它处理完最后一个被压缩数据时结束其本身,
    所以你并不需要明确地调用这个方法。然而,这个方法有益于检查
    数据是否正常地结束。

--- Zlib::Inflate#set_dictionary(string)

    设置preset dictionary并返回string。
    这个方法只要在出现Zlib::NeedDict意外之后才有用。
    详细信息请参考zlib.h。

--- Zlib::Inflate#sync(string)

    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.

    没明白作用……

--- Zlib::Inflate#sync_point?

    What is this?


== Zlib::GzipFile

用于处理gzip格式压缩文件的抽象的类。
其操作被定义在其子类中,
Zlib::GzipReader读取,Zlib::GzipWriter写入。

GzipReader should be used with associating an instance of IO class
(or an object which has the same methods as IO has).

=== SuperClass:

* Object

=== Class Methods:

--- Zlib::GzipFile.new(args...)

    See ((<Zlib::GzipReader.new>)) and ((<Zlib::GzipWriter.new>)).

--- Zlib::GzipFile.wrap(args...) {|gz| ... }

    See ((<Zlib::GzipReader.wrap>)) and ((<Zlib::GzipWriter.wrap>)).

--- Zlib::GzipFile.open(args...) {|gz| ... }

    See ((<Zlib::GzipReader.open>)) and ((<Zlib::GzipWriter.open>)).

=== Methods:

--- Zlib::GzipFile#closed?
--- Zlib::GzipFile#to_io

    Same as IO.

--- Zlib::GzipFile#close

    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).

    Zlib::GzipReader.open('hoge.gz') {|gz|
      print gz.read
    }

    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.

--- Zlib::GzipReader.open(filename)
--- Zlib::GzipReader.open(filename) {|gz| ... }

    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>)).

=== メソッド:

--- Zlib::GzipReader#eof
--- Zlib::GzipReader#eof?

    Returns true if the object reaches the end of compressed data.
    Note that eof? does ((*not*)) return true when reaches the
    end of ((*file*)).

--- Zlib::GzipReader#pos
--- Zlib::GzipReader#tell

    Returns the total bytes of data decompressed until now.
    Not that it does ((*not*)) the position of file pointer.

--- Zlib::GzipReader#each([rs])
--- Zlib::GzipReader#each_line([rs])
--- Zlib::GzipReader#each_byte([rs])
--- Zlib::GzipReader#gets([rs])
--- Zlib::GzipReader#getc
--- Zlib::GzipReader#lineno
--- Zlib::GzipReader#lineno=
--- Zlib::GzipReader#read([length])
--- Zlib::GzipReader#readchar
--- Zlib::GzipReader#readline([rs])
--- Zlib::GzipReader#readlines([rs])
--- Zlib::GzipReader#ungetc(char)

    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.

--- Zlib::GzipWriter.wrap(io[, level[, strategy]]) {|gz| ... }

    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.

--- Zlib::GzipWriter.open(filename[, level[, strategy]])
--- Zlib::GzipWriter.open(filename[, level[, strategy]]) {|gz| ... }

    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>)).


=== Methods:

--- Zlib::GzipWriter#close
--- Zlib::GzipWriter#finish

    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.*))

--- Zlib::GzipWriter#pos
--- Zlib::GzipWriter#tell

    Returns the total bytes of data compressed until now.
    Note that it does ((*not*)) the position of file pointer.

--- Zlib::GzipWriter#<< str
--- Zlib::GzipWriter#putc(ch)
--- Zlib::GzipWriter#puts(obj...)
--- Zlib::GzipWriter#print(arg...)
--- Zlib::GzipWriter#printf(format, arg...)
--- Zlib::GzipWriter#write(str)

    Same as IO.

--- Zlib::GzipWriter#flush([flush])

    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.


== Changes from 0.5 to 0.6

* New methods:

  * ((<Zlib::GzipFile.wrap>))
  * ((<Zlib::GzipFile#finish>))

* New constants:

  * ((<Zlib::ZLIB_VERSION>))
  * ((<Zlib::OS_VMCMS>))
  * ((<Zlib::OS_ZSYSTEM>))
  * ((<Zlib::OS_CPM>))
  * ((<Zlib::OS_QDOS>))
  * ((<Zlib::OS_RISCOS>))
  * ((<Zlib::OS_UNKNOWN>))

* Changed methods:

  * ((<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.

  * Classes

    * Deflate -> ((<Zlib::Deflate>))
    * Inflate -> ((<Zlib::Inflate>))
    * Zlib::Gzip -> ((<Zlib::GzipFile>))
    * GzipReader -> ((<Zlib::GzipReader>))
    * GzipWriter -> ((<Zlib::GzipWriter>))
    * Zlib::Gzip::Error -> ((<Zlib::GzipFile::Error>))
    * Zlib::GzipReader::NoFooter -> ((<Zlib::GzipFile::NoFooter>))
    * Zlib::GzipReader::CRCError -> ((<Zlib::GzipFile::CRCError>))
    * Zlib::GzipReader::LengthError -> ((<Zlib::GzipFile::LengthError>))

  * Constants

    * Zlib::ZStream::BINARY -> ((<Zlib::BINARY>))
    * Zlib::ZStream::ASCII -> ((<Zlib::ASCII>))
    * Zlib::ZStream::UNKNOWN -> ((<Zlib::UNKNOWN>))
    * Zlib::Deflate::NO_COMPRESSION -> ((<Zlib::NO_COMPRESSION>))
    * Zlib::Deflate::BEST_SPEED -> ((<Zlib::BEST_SPEED>))
    * Zlib::Deflate::BEST_COMPRESSION -> ((<Zlib::BEST_COMPRESSION>))
    * Zlib::Deflate::DEFAULT_COMPRESSION -> ((<Zlib::DEFAULT_COMPRESSION>))
    * Zlib::Deflate::FILTERED -> ((<Zlib::FILTERED>))
    * Zlib::Deflate::HUFFMAN_ONLY -> ((<Zlib::HUFFMAN_ONLY>))
    * Zlib::Deflate::DEFAULT_STRATEGY -> ((<Zlib::DEFAULT_STRATEGY>))
    * Zlib::Deflate::MAX_WBITS -> ((<Zlib::MAX_WBITS>))
    * Zlib::Deflate::DEF_MEM_LEVEL -> ((<Zlib::DEF_MEM_LEVEL>))
    * Zlib::Deflate::MAX_MEM_LEVEL -> ((<Zlib::MAX_MEM_LEVEL>))
    * Zlib::Deflate::NO_FLUSH -> ((<Zlib::NO_FLUSH>))
    * Zlib::Deflate::SYNC_FLUSH -> ((<Zlib::SYNC_FLUSH>))
    * Zlib::Deflate::FULL_FLUSH -> ((<Zlib::FULL_FLUSH>))
    * Zlib::Inflate::MAX_WBITS -> ((<Zlib::MAX_WBITS>))
    * Zlib::GzipReader::OS_* -> ((<Zlib::OS_*|Zlib::OS_CODE>))

  * Methods

    * Zlib::ZStream#flush_out -> ((<Zlib::ZStream#flush_next_out>))

* Made buffer for input (next_in).

* ((<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.

* Made all functions static.


=end
「If you judge people, you have no time to love them.」—— Mother Teresa
头像被屏蔽

Lv1.梦旅人 (禁止发言)

帅无敌

梦石
0
星屑
50
在线时间
2 小时
注册时间
2006-7-23
帖子
1313
3
发表于 2007-2-22 07:32:46 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
10 小时
注册时间
2006-12-2
帖子
201
4
发表于 2007-2-22 08:58:34 | 只看该作者
恩???
回复 支持 反对

使用道具 举报

Lv1.梦旅人

查无此人

梦石
0
星屑
50
在线时间
9 小时
注册时间
2006-5-8
帖子
1399
5
发表于 2007-2-22 20:53:58 | 只看该作者
水平有限, 如看天书.......
KRKR + NS 学习中..........
回复 支持 反对

使用道具 举报

Lv2.观梦者


  • 更新完成啦

梦石
0
星屑
759
在线时间
6267 小时
注册时间
2006-6-7
帖子
8462
6
发表于 2007-2-22 21:40:18 | 只看该作者
看不懂{/fd}前面的还能理解一点{/gg}
回复 支持 反对

使用道具 举报

Lv1.梦旅人

月下可怜人

梦石
0
星屑
50
在线时间
10 小时
注册时间
2005-11-23
帖子
4085

第1届短篇游戏比赛亚军

7
发表于 2007-2-22 22:31:38 | 只看该作者
这个真不错,最近正在用Zlib::Deflate预先存储图象坐标数据以减少临时数据的体积.另存.
纵然千里外,我等雁归来。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

天国守护

8
发表于 2007-2-22 23:06:35 | 只看该作者
这个没翻译完?先把标题改过来先~~~~~
今天我这里到是热闹起来了~~~呵呵~~~~{/cy}
很久很久没有来了  看一下注册时间 10年都过去了~  虽然66RPG不再是那个66RPG 但是毕竟这里给我留下了 很多的回忆  亲爱的朋友们 你们还好吗?
回复 支持 反对

使用道具 举报

Lv2.观梦者


  • 更新完成啦

梦石
0
星屑
759
在线时间
6267 小时
注册时间
2006-6-7
帖子
8462
9
发表于 2007-2-23 18:23:41 | 只看该作者
原来是这样- -
终于知道索什么了
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
9 小时
注册时间
2007-2-19
帖子
21
10
发表于 2007-2-24 23:12:32 | 只看该作者
呃 zlib压缩模块 - - 辛苦啦 努力学习中 ~
冰冷的雪花
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-25 16:44

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表