FreeBSD/contrib/subversion/subversion/libsvn_subr/stream.c
/* Compress data and write it to the substream */
Compress data and write it to the substream
Compress data and write it to the substream
static svn_error_t *
write_handler_gz(void *baton, const char *buffer, apr_size_t *len)
{
  struct zbaton *btn = baton;
  apr_pool_t *subpool;
  void *write_buf;
  apr_size_t buf_size, write_len;
  int zerr;
  if (btn->out == NULL)
    {
      btn->out = apr_palloc(btn->pool, sizeof(z_stream));
      btn->out->zalloc = zalloc;
      btn->out->zfree = zfree;
      btn->out->opaque =  btn->pool;
      zerr = deflateInit(btn->out, Z_DEFAULT_COMPRESSION);
      SVN_ERR(svn_error__wrap_zlib(zerr, "deflateInit", btn->out->msg));
    }
  buf_size = *len + (*len / 1000) + 13;
  subpool = svn_pool_create(btn->pool);
  write_buf = apr_palloc(subpool, buf_size);
  btn->out->next_in = (Bytef *) buffer;  
  btn->out->avail_in = (uInt) *len;
  while (btn->out->avail_in > 0)
    {
      btn->out->next_out = write_buf;
      btn->out->avail_out = (uInt) buf_size;
      zerr = deflate(btn->out, Z_NO_FLUSH);
      SVN_ERR(svn_error__wrap_zlib(zerr, "deflate", btn->out->msg));
      write_len = buf_size - btn->out->avail_out;
      if (write_len > 0)
        SVN_ERR(svn_stream_write(btn->substream, write_buf, &write_len));
    }
  svn_pool_destroy(subpool);
  return SVN_NO_ERROR;
}
static svn_error_t * write_handler_gz ( void * baton , const char * buffer , apr_size_t * len ) { struct zbaton * btn = baton ; apr_pool_t * subpool ; void * write_buf ; apr_size_t buf_size , write_len ; int zerr ; if ( btn -> out == NULL ) { btn -> out = apr_palloc ( btn -> pool , sizeof ( z_stream ) ) ; btn -> out -> zalloc = zalloc ; btn -> out -> zfree = zfree ; btn -> out -> opaque = btn -> pool ; zerr = deflateInit ( btn -> out , Z_DEFAULT_COMPRESSION ) ; SVN_ERR ( svn_error__wrap_zlib ( zerr , " " , btn -> out -> msg ) ) ; } buf_size = * len + ( * len / 1000 ) + 13 ; subpool = svn_pool_create ( btn -> pool ) ; write_buf = apr_palloc ( subpool , buf_size ) ; btn -> out -> next_in = ( Bytef * ) buffer ; btn -> out -> avail_in = ( uInt ) * len ; while ( btn -> out -> avail_in > 0 ) { btn -> out -> next_out = write_buf ; btn -> out -> avail_out = ( uInt ) buf_size ; zerr = deflate ( btn -> out , Z_NO_FLUSH ) ; SVN_ERR ( svn_error__wrap_zlib ( zerr , " " , btn -> out -> msg ) ) ; write_len = buf_size - btn -> out -> avail_out ; if ( write_len > 0 ) SVN_ERR ( svn_stream_write ( btn -> substream , write_buf , & write_len ) ) ; } svn_pool_destroy ( subpool ) ; return SVN_NO_ERROR ; }
Compress data and write it to the substream
Compress data and write it to the substream
/* The largest buffer we should need is 0.1% larger than the
     compressed data, + 12 bytes. This info comes from zlib.h.  */ /* Casting away const! */