]>
git.saurik.com Git - wxWidgets.git/blob - src/zlib/compress.c
   1 /* compress.c -- compress a memory buffer 
   2  * Copyright (C) 1995-2002 Jean-loup Gailly. 
   3  * For conditions of distribution and use, see copyright notice in zlib.h 
   8 #include "../zlib/zlib.h" 
  10 /* =========================================================================== 
  11      Compresses the source buffer into the destination buffer. The level 
  12    parameter has the same meaning as in deflateInit.  sourceLen is the byte 
  13    length of the source buffer. Upon entry, destLen is the total size of the 
  14    destination buffer, which must be at least 0.1% larger than sourceLen plus 
  15    12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 
  17      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 
  18    memory, Z_BUF_ERROR if there was not enough room in the output buffer, 
  19    Z_STREAM_ERROR if the level parameter is invalid. 
  21 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ 
  22 int ZEXPORT 
compress2 (Bytef
* dest
, uLongf
* destLen
, const Bytef
* source
, uLong sourceLen
, int level
) 
  24 int ZEXPORT 
compress2 (dest
, destLen
, source
, sourceLen
, level
) 
  35     stream
.next_in 
= (Bytef
*)source
; 
  36     stream
.avail_in 
= (uInt
)sourceLen
; 
  38     /* Check for source > 64K on 16-bit machine: */ 
  39     if ((uLong
)stream
.avail_in 
!= sourceLen
) return Z_BUF_ERROR
; 
  41     stream
.next_out 
= dest
; 
  42     stream
.avail_out 
= (uInt
)*destLen
; 
  43     if ((uLong
)stream
.avail_out 
!= *destLen
) return Z_BUF_ERROR
; 
  45     stream
.zalloc 
= (alloc_func
)0; 
  46     stream
.zfree 
= (free_func
)0; 
  47     stream
.opaque 
= (voidpf
)0; 
  49     err 
= deflateInit(&stream
, level
); 
  50     if (err 
!= Z_OK
) return err
; 
  52     err 
= deflate(&stream
, Z_FINISH
); 
  53     if (err 
!= Z_STREAM_END
) { 
  55         return err 
== Z_OK 
? Z_BUF_ERROR 
: err
; 
  57     *destLen 
= stream
.total_out
; 
  59     err 
= deflateEnd(&stream
); 
  63 /* =========================================================================== 
  65 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ 
  66 int ZEXPORT 
compress (Bytef
* dest
, uLongf
* destLen
, const Bytef
* source
, uLong sourceLen
) 
  68 int ZEXPORT 
compress (dest
, destLen
, source
, sourceLen
) 
  75     return compress2(dest
, destLen
, source
, sourceLen
, Z_DEFAULT_COMPRESSION
);