Branch: Tag:

2016-09-26

2016-09-26 11:25:53 by Stephen R. van den Berg <srb@cuci.nl>

Gz.deflate: Add clone() method; allows for testing compression.

Gz.File: Support setting the window_size in setparams().
Gz: Support Z_BLOCK and Z_FULL_FLUSH.

12:    protected private Stdio.Stream f;    protected private inflate inf;    protected private deflate def; -  protected private int level, strategy; +  protected private int level, strategy, window_size;    protected private string read_buf;    protected private int file_pos, crc, write_mode, at_eof;   
95:    write_mode = 0;    level = 6;    strategy = DEFAULT_STRATEGY; +  window_size = 15;    if(mode) {    mode = filter(mode, lambda(int n) {    if(n == 'w' || n == 'a')
203:    //! the number of bytes written to the file.    int write(string data)    { -  if(!def) def = deflate(-level, strategy); +  if(!def) def = deflate(-level, strategy, window_size);    string comp = def->deflate(data, NO_FLUSH);    if(f->write(comp) != sizeof(comp))    return 0;
284:    return at_eof;    }    -  //! Sets the encoding level and strategy -  //! @param level -  //! Level of the compression. -  //! 0 is the least compression, 9 is max. 8 is default. -  //! @param strategy -  //! Set strategy for encoding to one of the following: -  //! DEFAULT_STRATEGY -  //! FILTERED -  //! HUFFMAN_ONLY -  int setparams(int level, int strategy) -  { -  if(def) { +  //! Sets the encoding level, strategy and window_size. +  //! +  //! @seealso +  //! @[Gz.deflate] +  int setparams(void|int(-9..9) level, void|int strategy, +  void|int(8..15) window_size) { +  if (def) {    string s = def->deflate("", SYNC_FLUSH); -  if(sizeof(s) && f->write(s) != sizeof(s)) +  if (sizeof(s) && f->write(s) != sizeof(s))    return 0;    def = 0;    } -  +  if (!zero_type(level))    _file::level = level; -  +  if (!zero_type(strategy))    _file::strategy = strategy; -  +  if (!zero_type(window_size)) +  _file::window_size = window_size;    return 1;    }