BZip2Stream.st
changeset 1570 b6dd9a871cc2
parent 1564 c3409f17ded6
child 1750 436ca57ad6be
equal deleted inserted replaced
1569:6373292f574f 1570:b6dd9a871cc2
    88     }
    88     }
    89 %}.
    89 %}.
    90 !
    90 !
    91 
    91 
    92 zdeflate
    92 zdeflate
    93     "low level - deflate
    93     "low level - deflate"
    94     "
    94 
    95     |errorNo|
    95     |errorNo|
    96 
       
    97     errorNo := nil.
    96     errorNo := nil.
    98 
    97 %{
    99 %{
    98     OBJ _zstreamObj = __INST( zstream );
   100     OBJ _zstreamObj = __INST( zstream );
    99 
   101 
   100     if( _zstreamObj != nil )
   102     if( _zstreamObj != nil )
   101     {
   103     {
   102         int          _errorNo, _action;
   104 	int          _errorNo, _action;
   103         unsigned int _bfsize;
   105 	unsigned int _bfsize;
   104         zstream_s *  _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
   106 	zstream_s *  _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
   105 
   107 
   106         if( _zstream->op_mode != e_opmode_deflate )
   108 	if( _zstream->op_mode != e_opmode_deflate )
   107             RETURN( nil );
   109 	    RETURN( nil );
   108 
   110 
   109         _bfsize = _zstream->out_total;
   111 	_bfsize = _zstream->out_total;
   110 
   112 
   111         if( _zstream->stream.state == NULL )
   113 	if( _zstream->stream.state == NULL )
   112         {
   114 	{
   113             _zstream->op_mode = e_opmode_unspecified;
   115 	    _zstream->op_mode = e_opmode_unspecified;
   114             RETURN( nil );
   116 	    RETURN( nil );
   115         }
   117 	}
   116         _action = (__INST(hitEOF) == true) ? BZ_FINISH : BZ_RUN;        
   118 	_action = (__INST(hitEOF) == true) ? BZ_FINISH : BZ_RUN;        
   117 
   119 
   118         _zstream->stream.avail_out = _bfsize;
   120 	_zstream->stream.avail_out = _bfsize;
   119         _zstream->stream.next_out  = _zstream->out_ref;
   121 	_zstream->stream.next_out  = _zstream->out_ref;
       
   122         
   120         
   123 	_errorNo = BZ2_bzCompress( & _zstream->stream, _action );
   121         _errorNo = BZ2_bzCompress( & _zstream->stream, _action );
   124 
   122 
   125 	if( _errorNo == BZ_STREAM_END )
   123         if( _errorNo == BZ_STREAM_END )
   126 	{
   124         {
   127 	    _zstream->stream.avail_in = 0;
   125             _zstream->stream.avail_in = 0;
   128 	    _zstream->stream.next_in  = NULL;
   126             _zstream->stream.next_in  = NULL;
   129 	    _errorNo = BZ2_bzCompressEnd( & _zstream->stream );
   127             _errorNo = BZ2_bzCompressEnd( & _zstream->stream );
   130 	}
   128         }
   131 
   129 
   132 	if(   (_errorNo == BZ_OK)
   130         if(   (_errorNo == BZ_OK)
   133 	   || (_errorNo == BZ_RUN_OK)
   131            || (_errorNo == BZ_RUN_OK)
   134 	   || (_errorNo == BZ_FINISH_OK)
   132            || (_errorNo == BZ_FINISH_OK)
   135 	  )
   133           )
   136 	{
   134         {
   137 	    if(   (_zstream->stream.avail_out != _bfsize)
   135             if(   (_zstream->stream.avail_out != _bfsize)
   138 	       || (_zstream->stream.avail_in  != 0)
   136                || (_zstream->stream.avail_in  != 0)
   139 	      )
   137               )
   140 	      RETURN( true );
   138               RETURN( true );
   141 
   139 
   142 	    RETURN( false );
   140             RETURN( false );
   143 	}
   141         }
   144 	errorNo = __MKSMALLINT( _errorNo );
   142         errorNo = __MKSMALLINT( _errorNo );
   145     }
   143     }
   146 %}.
   144 %}.
   147     errorNo ifNil:[
   145     errorNo ifNil:[
   148 	zstream ifNil:[self errorNotOpen].
   146         zstream ifNil:[self errorNotOpen].
   149 	self invalidArguments.
   147         self invalidArgument.
   150     ].
   148     ].
   151     self zerror:errorNo.
   149     self zerror:errorNo.
   152 !
   150 !
   153 
   151 
   154 zdeflateInit
   152 zdeflateInit
   155     "low level - open for reading
   153     "low level - open for reading"
   156     "
   154 
   157     |errorNo blockSize100k workFactor|
   155     |errorNo blockSize100k workFactor|
   158 
   156 
   159     errorNo       := nil.
   157     errorNo       := nil.
   160     blockSize100k := BlockSize.
   158     blockSize100k := BlockSize.
   161     workFactor    := 30.
   159     workFactor    := 30.
   162 %{
   160 %{
   163     OBJ _zstreamObj = __INST( zstream );
   161     OBJ _zstreamObj = __INST( zstream );
   164 
   162 
   165     if( (_zstreamObj != nil) && __bothSmallInteger(blockSize100k, workFactor) )
   163     if( (_zstreamObj != nil) && __bothSmallInteger(blockSize100k, workFactor) )
   166     {
   164     {
   167 	int         _errorNo;
   165         int         _errorNo;
   168 	zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
   166         zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
   169 
   167 
   170 	_zstream->op_mode = e_opmode_deflate;
   168         _zstream->op_mode = e_opmode_deflate;
   171 
   169 
   172 	_errorNo = BZ2_bzCompressInit( & _zstream->stream
   170         _errorNo = BZ2_bzCompressInit( & _zstream->stream
   173 				     , __intVal( blockSize100k ), 0, __intVal( workFactor ) );
   171                                      , __intVal( blockSize100k ), 0, __intVal( workFactor ) );
   174 
   172 
   175 	if( _errorNo == BZ_OK )
   173         if( _errorNo == BZ_OK )
   176 	    RETURN( self );
   174             RETURN( self );
   177 
   175 
   178 	errorNo = __MKSMALLINT( _errorNo );
   176         errorNo = __MKSMALLINT( _errorNo );
   179     }
   177     }
   180 %}.
   178 %}.
   181     errorNo ifNil:[
   179     errorNo ifNil:[
   182 	zstream ifNil:[ self errorNotOpen ].
   180         zstream ifNil:[ self errorNotOpen ].
   183 	self invalidArguments .
   181         self invalidArgument.
   184     ].
   182     ].
   185     self zerror:errorNo.
   183     self zerror:errorNo.
   186 !
   184 !
   187 
   185 
   188 zget_avail_out
   186 zget_avail_out
   323     }
   321     }
   324 %}.
   322 %}.
   325 !
   323 !
   326 
   324 
   327 zset_avail_in:count
   325 zset_avail_in:count
   328     "set the 'avail_in'
   326     "set the 'avail_in'"
   329     "
       
   330 %{
   327 %{
   331     OBJ _zstreamObj = __INST( zstream );
   328     OBJ _zstreamObj = __INST( zstream );
   332 
   329 
   333     if( (_zstreamObj != nil) && __isSmallInteger(count) )
   330     if( (_zstreamObj != nil) && __isSmallInteger(count) )
   334     {
   331     {
   335 	int         _count;
   332         int         _count;
   336 	zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
   333         zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
   337 
   334 
   338 	if( (_count = __intVal( count )) > 0 )
   335         if( (_count = __intVal( count )) > 0 )
   339 	{
   336         {
   340 	    char * _in_ref = _zstream->in_ref;
   337             char * _in_ref = _zstream->in_ref;
   341 
   338 
   342 	    _zstream->stream.avail_in = _count;
   339             _zstream->stream.avail_in = _count;
   343 	    _zstream->stream.next_in  = _in_ref;
   340             _zstream->stream.next_in  = _in_ref;
   344 	} else {
   341         } else {
   345 	    _zstream->stream.avail_in = 0;
   342             _zstream->stream.avail_in = 0;
   346 	    _zstream->stream.next_in  = NULL;
   343             _zstream->stream.next_in  = NULL;
   347 	}
   344         }
   348 	RETURN( self );
   345         RETURN( self );
   349     }
   346     }
   350 %}.
   347 %}.
   351     zstream ifNil:[ self errorNotOpen ].
   348     zstream ifNil:[ self errorNotOpen ].
   352     self invalidArguments.
   349     self invalidArgument.
   353 ! !
   350 ! !
   354 
   351 
   355 !BZip2Stream class methodsFor:'documentation'!
   352 !BZip2Stream class methodsFor:'documentation'!
   356 
   353 
   357 version
   354 version
   358     ^ '$Header: /cvs/stx/stx/libbasic2/BZip2Stream.st,v 1.8 2005-07-08 17:30:34 cg Exp $'
   355     ^ '$Header: /cvs/stx/stx/libbasic2/BZip2Stream.st,v 1.9 2005-08-01 12:37:43 stefan Exp $'
   359 ! !
   356 ! !