FreeBSD/contrib/subversion/subversion/libsvn_subr/stream.c
/* Handle reading from a compressed stream */
Handle reading from a compressed stream
Handle reading from a compressed stream
static svn_error_t *
read_handler_gz(void *baton, char *buffer, apr_size_t *len)
{
  struct zbaton *btn = baton;
  int zerr;
  if (btn->in == NULL)
    {
      btn->in = apr_palloc(btn->pool, sizeof(z_stream));
      btn->in->zalloc = zalloc;
      btn->in->zfree = zfree;
      btn->in->opaque = btn->pool;
      btn->read_buffer = apr_palloc(btn->pool, ZBUFFER_SIZE);
      btn->in->next_in = btn->read_buffer;
      btn->in->avail_in = ZBUFFER_SIZE;
      SVN_ERR(read_helper_gz(btn->substream, btn->read_buffer,
                             &btn->in->avail_in, &btn->read_flush));
      zerr = inflateInit(btn->in);
      SVN_ERR(svn_error__wrap_zlib(zerr, "inflateInit", btn->in->msg));
    }
  btn->in->next_out = (Bytef *) buffer;
  btn->in->avail_out = (uInt) *len;
  while (btn->in->avail_out > 0)
    {
      if (btn->in->avail_in <= 0)
        {
          btn->in->avail_in = ZBUFFER_SIZE;
          btn->in->next_in = btn->read_buffer;
          SVN_ERR(read_helper_gz(btn->substream, btn->read_buffer,
                                 &btn->in->avail_in, &btn->read_flush));
        }
      if (btn->in->avail_in == 0)
        {
          *len = 0;
          return SVN_NO_ERROR;
        }
      zerr = inflate(btn->in, btn->read_flush);
      if (zerr == Z_STREAM_END)
        break;
      else if (zerr != Z_OK)
        return svn_error_trace(svn_error__wrap_zlib(zerr, "inflate",
                                                    btn->in->msg));
    }
  *len -= btn->in->avail_out;
  return SVN_NO_ERROR;
}
static svn_error_t * read_handler_gz ( void * baton , char * buffer , apr_size_t * len ) { struct zbaton * btn = baton ; int zerr ; if ( btn -> in == NULL ) { btn -> in = apr_palloc ( btn -> pool , sizeof ( z_stream ) ) ; btn -> in -> zalloc = zalloc ; btn -> in -> zfree = zfree ; btn -> in -> opaque = btn -> pool ; btn -> read_buffer = apr_palloc ( btn -> pool , ZBUFFER_SIZE ) ; btn -> in -> next_in = btn -> read_buffer ; btn -> in -> avail_in = ZBUFFER_SIZE ; SVN_ERR ( read_helper_gz ( btn -> substream , btn -> read_buffer , & btn -> in -> avail_in , & btn -> read_flush ) ) ; zerr = inflateInit ( btn -> in ) ; SVN_ERR ( svn_error__wrap_zlib ( zerr , " " , btn -> in -> msg ) ) ; } btn -> in -> next_out = ( Bytef * ) buffer ; btn -> in -> avail_out = ( uInt ) * len ; while ( btn -> in -> avail_out > 0 ) { if ( btn -> in -> avail_in <= 0 ) { btn -> in -> avail_in = ZBUFFER_SIZE ; btn -> in -> next_in = btn -> read_buffer ; SVN_ERR ( read_helper_gz ( btn -> substream , btn -> read_buffer , & btn -> in -> avail_in , & btn -> read_flush ) ) ; } if ( btn -> in -> avail_in == 0 ) { * len = 0 ; return SVN_NO_ERROR ; } zerr = inflate ( btn -> in , btn -> read_flush ) ; if ( zerr == Z_STREAM_END ) break ; else if ( zerr != Z_OK ) return svn_error_trace ( svn_error__wrap_zlib ( zerr , " " , btn -> in -> msg ) ) ; } * len -= btn -> in -> avail_out ; return SVN_NO_ERROR ; }
Handle reading from a compressed stream
Handle reading from a compressed stream
/* Short read means underlying stream has run out. */