pike.git / src / modules / Gz / module.pmod.in

version» Context lines:

pike.git/src/modules/Gz/module.pmod.in:1: - // $Id: module.pmod.in,v 1.9 2003/04/14 17:10:57 marcus Exp $ + // $Id: module.pmod.in,v 1.10 2003/04/15 13:39:31 marcus Exp $   #pike __REAL_VERSION__      inherit @module@;      //! Low-level implementation of read/write support for GZip files   class _file {       static private Stdio.Stream f;    static private inflate inf;    static private deflate def;
pike.git/src/modules/Gz/module.pmod.in:92:    else    return 1;    });    if(write_mode) {    if(!has_value(mode, 'a'))    mode += "t";    mode += "c";    }    }    file_pos = 0; +  crc = crc32("");    if(objectp(file))    f = file;    else {    f = Stdio.File();    if(!f->open(file, mode||"rb"))    return 0;    }    return write_mode? make_header() : check_header();    }   
pike.git/src/modules/Gz/module.pmod.in:143:    if(!inf) inf = inflate(-15);    while(sizeof(read_buf) < len) {    string r = f->read(16384);    if(!sizeof(r))    break;    read_buf += inf->inflate(r);    }    string res = read_buf[..len-1];    read_buf = read_buf[len..];    file_pos += sizeof(res); +  crc = crc32(res, crc);    return res;    }       //! Writes the data to the file.    //! @returns    //! the number of bytes written to the file.    int write(string data)    { -  if(!def) { def = deflate(-level, strategy); crc = crc32(""); } +  if(!def) def = deflate(-level, strategy);    string comp = def->deflate(data, NO_FLUSH);    if(f->write(comp) != sizeof(comp))    return 0;    else {    file_pos += sizeof(data);    crc = crc32(data, crc);    return sizeof(data);    }    }   
pike.git/src/modules/Gz/module.pmod.in:196:    return file_pos;    } else {    if(type == SEEK_CUR)    pos += file_pos;    if(pos < 0)    return -1;    if(!f->seek || f->seek(0)<0)    return -1;    file_pos = 0;    read_buf = ""; +  crc = crc32("");    while(pos > 0) {    string r = read(pos>16384? 16384:pos);    if(!sizeof(r))    return -1;    pos -= sizeof(r);    }    return file_pos;    }    }   
pike.git/src/modules/Gz/module.pmod.in:238:    //! 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) { -  string s = def->deflate("", FINISH); +  string s = def->deflate("", SYNC_FLUSH);    if(sizeof(s) && f->write(s) != sizeof(s))    return 0;    def = 0;    }    _file::level = level;    _file::strategy = strategy;    return 1;    }      }