Hi

Try using my code, it works fine with large textfiles.

int gzip(FileHand inf, FileHand outf)
{
  z_stream                      gzipit;
  int                           readgot, isav;
  unsigned long         crc32val, itotal, total = 0;
  unsigned char         ibuf[BSIZ], obuf[ZBSIZ];
  
 
/*to use the deflate function the gzipit structure has to be initialised*/
  memset(&gzipit, 0, sizeof(gzipit));

  FileTell(inf,(long *)&itotal, NULL);

  crc32val = CRCVAL_INITIAL;

  gzipit.next_out = ibuf;
  gzipit.avail_out = BSIZ;

/*initialise all needed structures*/
  ZLSetup;
  if(deflateInit2(&gzipit, /* level */ 8, 8,/* bits */ 13, /* memlevel */ 6, 0) != 
Z_OK)return -1;
  readgot = ZBSIZ;


/*read the file as long as ZBSIZ long pieces can be read*/
  while (!FileEOF(inf) && readgot == ZBSIZ) 
  {
    obuf[0]=chrNull;
    if (0 >= (readgot = FileRead(inf, obuf,1 , ZBSIZ, NULL)))
      break;

    crc32val = crc32(crc32val, obuf, readgot);
    total += readgot;

/*set the next-in next-out pointer, compress the data and write it into the outf file*/
    gzipit.next_in = obuf;
    gzipit.avail_in =readgot;

    while (gzipit.avail_in || readgot !=ZBSIZ) 
    {
      isav = deflate(&gzipit, readgot == ZBSIZ ? 0 : Z_FINISH);      
      if(isav<0)
      {
        deflateEnd(&gzipit);
        return -1;
      }
      
      if( gzipit.avail_out == BSIZ ) /* no bytes added */
                                                                        break;
      FileWrite(outf, ibuf, 1, BSIZ - gzipit.avail_out, NULL);

      gzipit.next_out = ibuf;
          gzipit.avail_out = BSIZ;
      
    }

  }

/*the rest of the data that is smaller as ZBSIZ has to be compressed*/
  isav = deflate(&gzipit, Z_FINISH);
  FileWrite(outf, ibuf, 1, BSIZ - gzipit.avail_out, NULL);  
  if(isav<0)
  {
        deflateEnd(&gzipit);
        return -1;
  }

/*if any error occured the function exits immediately*/
  isav = deflateEnd(&gzipit);
  if(isav<0)
        return -1;

  memcpy(ibuf,&crc32val,4);
  itotal = LG(ibuf);
  FileWrite(outf, &itotal, 1, 4, NULL);
  memcpy(ibuf,&total,4);
  itotal = LG(ibuf);
  FileWrite(outf, &itotal, 1, 4, NULL);
  
  return 0;
}

Christian

"Palm Developer Forum" <[EMAIL PROTECTED]> schrieb am 28.07.04 08:14:15:
> 
> I'm trying to compress a set of text files using this library...
> 
> I've been running into problems with files that are 32k or larger. I keep getting a 
> Z_MEM_ERROR.
> 
> In the manual for the library it doesn't mention the fact that you can't compress 
> anything larger then 32k. Does anyone know if this is a limitation? Or is it 
> something to do with the text file.
> 
> I've taken a 24k text file that i know that works and have copy and pasted some of 
> the text to make it 32k. Still comes up with the same error.
> 
> any insights would be appreciated.
> -- 
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
> http://www.palmos.com/dev/support/forums/


_______________________________________________________
WEB.DE Video-Mail - Sagen Sie mehr mit bewegten Bildern
Informationen unter: http://freemail.web.de/?mc=021199


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to