# HG changeset patch # User ca # Date 1024981506 -7200 # Node ID 9df4a60df0ef52e9e832a154483919d25935b856 # Parent 44871623590bd9bbbd3f9b18bc99409a5dae9cf2 *** empty log message *** diff -r 44871623590b -r 9df4a60df0ef ZipStream.st --- a/ZipStream.st Mon Jun 24 12:14:06 2002 +0200 +++ b/ZipStream.st Tue Jun 25 07:05:06 2002 +0200 @@ -356,7 +356,7 @@ zstream := nil. ! -zdeflate:finishing +zdeflate "low level - deflate " |errorNo| @@ -373,7 +373,7 @@ zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); if( _zstream->op_mode != e_opmode_deflate ) - RETURN( nil ); + RETURN( false ); _bfsize = _zstream->out_total; @@ -399,7 +399,7 @@ _zstream->stream.avail_out = _bfsize; _zstream->stream.next_out = _zstream->out_ref; - _action = (finishing == true) ? Z_FINISH : Z_NO_FLUSH; + _action = (__INST(hitEOF) == true) ? Z_FINISH : Z_NO_FLUSH; _errorNo = deflate( & _zstream->stream, _action ); if( _errorNo == Z_STREAM_END ) @@ -470,34 +470,6 @@ self zerror:errorNo. ! -zflush - |count| - - count := 0. - -%{ - OBJ _zstreamObj = __INST( zstream ); - - if( _zstreamObj != nil ) - { - uInt _count; - zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); - - _count = _zstream->out_total - _zstream->stream.avail_out; - - if( _count == 0 ) - RETURN( __MKSMALLINT(0) ); - - _zstream->stream.avail_out = _zstream->out_total; - _zstream->stream.next_out = _zstream->out_ref; - - count = __MKSMALLINT( _count ); - } -%}. - zstream ifNil:[ self errorNotOpen ]. - self onStreamPutBytes:count from:outputBytes. -! - zinflate "low level - inflate " @@ -552,6 +524,25 @@ self zerror:errorNo. ! +zget_avail_out + "low level - get the number of available out bytes + " +%{ + OBJ _zstreamObj = __INST( zstream ); + + if( _zstreamObj != nil ) + { + uInt _count; + zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); + + _count = _zstream->out_total - _zstream->stream.avail_out; + + RETURN( __MKSMALLINT (_count) ); + } +%}. + self errorNotOpen. +! + zinflateInit "low level - inflateInit " @@ -808,17 +799,12 @@ close "close the zip-stream " - zstream ifNil:[^ self]. - - self isWriteOpen ifTrue:[ - self flush. + hitEOF := true. - [ self zflush. - self zdeflate:true - ] whileTrue. - + zstream ifNotNil:[ + self flush. + self zclose. ]. - self zclose. ! readOpenOn:aStream @@ -847,16 +833,20 @@ |continue| self isWriteOpen ifFalse:[ ^ self ]. + self zset_avail_in:position. - self zset_avail_in:position. position := 0. continue := true. - [continue] whileTrue:[ - self zflush. - continue := self zdeflate:false. + [continue] whileTrue:[ |count| + count := self zget_avail_out. + + count > 0 ifTrue:[ + self onStreamPutBytes:count from:outputBytes + ]. + continue := self zdeflate. ]. -! +! nextPut:something "write the argument, something @@ -869,6 +859,9 @@ if( __INST(mode) == @symbol(writeonly) ) { + if( __INST(hitEOF) != false ) + goto bad; + if( __INST(binary) != true ) { if( ! __isCharacter(something) ) @@ -890,7 +883,14 @@ } bad: ; %}. - byte ifNil:[self invalidArguments]. + + byte ifNil:[ + mode == #writeonly ifFalse:[ + zstream ifNil:[ self errorNotOpen ]. + self errorReadOnly. + ]. + self invalidArguments. + ]. position == inputBytes size ifTrue:[ self flush ]. position := position + 1. inputBytes at:position put:byte. @@ -911,6 +911,6 @@ !ZipStream class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.12 2002-06-24 10:14:06 ca Exp $' + ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.13 2002-06-25 05:05:06 ca Exp $' ! ! ZipStream initialize!