--- a/ZipStream.st Thu Jun 20 10:57:17 2002 +0200
+++ b/ZipStream.st Thu Jun 20 13:15:02 2002 +0200
@@ -24,6 +24,11 @@
#include "compress/zlib.h"
#include "compress/zutil.h"
+typedef enum { e_infalteInit
+ , e_infalteLoop
+ , e_infalteEnd
+} e_infalte;
+
typedef struct {
z_stream stream;
Bytef * in_ref;
@@ -34,8 +39,8 @@
uLong out_position;
uLong out_total;
uLong out_limit;
- uLong out_atStreamEnd;
+ e_infalte inflateMode;
uLong crc_32;
} zstream_s;
@@ -266,8 +271,6 @@
|errorNo|
errorNo := nil.
-" hitEOF == true ifTrue:[^ 0].
-"
%{
OBJ _zstreamObj = __INST( zstream );
@@ -276,16 +279,27 @@
zstream_s * _zstream;
int _errorNo;
- _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
- _zstream->out_position = 0;
+ _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
- if( _zstream->out_atStreamEnd )
+ /* still data available */
+ if( _zstream->out_position < _zstream->out_limit )
+ RETURN( __MKSMALLINT (0) );
+
+ _zstream->out_position = _zstream->out_limit = 0;
+
+ if( _zstream->inflateMode != e_infalteLoop )
{
- _zstream->out_limit = 0;
- __INST(hitEOF) = true;
+ if( _zstream->inflateMode == e_infalteEnd )
+ {
+ __INST(hitEOF) = true;
+ RETURN( __MKSMALLINT (0) );
+ }
- RETURN( __MKSMALLINT (0) )
- }
+ if( _zstream->stream.avail_in == 0 )
+ RETURN( __MKSMALLINT (0) );
+
+ _zstream->inflateMode = e_infalteLoop;
+ }
_zstream->stream.avail_out = _zstream->out_total;
_zstream->stream.next_out = _zstream->out_ref;
@@ -294,14 +308,13 @@
if( _errorNo == Z_STREAM_END )
{
_errorNo = inflateEnd( & _zstream->stream );
- _zstream->out_atStreamEnd = 1;
+ _zstream->inflateMode = e_infalteEnd;
}
if( _errorNo == Z_OK )
{
uInt _limit = _zstream->out_total - _zstream->stream.avail_out;
_zstream->out_limit = _limit;
- _zstream->out_position = 0;
_zstream->stream.avail_out = 0;
_zstream->stream.next_out = Z_NULL;
@@ -360,6 +373,31 @@
self invalidArguments .
!
+zNextByte
+%{
+ OBJ _zstreamObj = __INST( zstream );
+
+ if( _zstreamObj != nil )
+ {
+ zstream_s * _zstream;
+ uInt _outPos;
+
+ _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
+ _outPos = _zstream->out_position;
+
+ if( _outPos < _zstream->out_limit )
+ {
+ int _theByte = (Byte) _zstream->out_ref[ _outPos ];
+ _zstream->out_position += 1;
+
+ RETURN( __MKSMALLINT (_theByte) );
+ }
+ RETURN( nil );
+ }
+%}.
+ self errorNotOpen.
+!
+
zNextPutByte:aByte
%{
OBJ _zstreamObj = __INST( zstream );
@@ -733,13 +771,14 @@
_zstream->out_position = 0;
_zstream->out_limit = 0;
- _zstream->out_atStreamEnd = 0;
_zstream->out_total = __intVal( outTotal );
_zstream->out_ref = (Bytef *) __externalBytesAddress( _outObj );
_zstream->stream.next_out = _zstream->out_ref;
_zstream->stream.avail_out = _zstream->out_total;
_zstream->stream.total_out = 0;
+ _zstream->inflateMode = e_infalteInit;
+
_zstream->stream.zalloc = (alloc_func)0;
_zstream->stream.zfree = (free_func) 0;
_zstream->stream.opaque = (voidpf) 0;
@@ -969,6 +1008,7 @@
|count offs|
self isReadOpen ifFalse:[ self pastEnd ].
+ self atEnd ifTrue:[ ^ 0 ].
count := aCount.
offs := start.
@@ -997,14 +1037,18 @@
!
nextByte
- |buff size|
+ |byte bytes|
+
+ byte := self zNextByte.
+ byte ifNotNil:[ ^ byte ].
- buff := ByteArray new:1.
- size := self nextAvailableBytes:1 into:buff startingAt:1.
+ bytes := ByteArray new:1.
- size ~~ 0 ifTrue:[
- ^ buff at:1
+ (self nextAvailableBytes:1 into:bytes startingAt:1) == 1 ifTrue:[
+ ^ bytes at:1
].
+ "end of file detected
+ "
^ nil
! !
@@ -1030,17 +1074,12 @@
!
readOpenOn:aStream
- |n|
isReadOpen := true.
self zopen:aStream.
self zinflateInit.
self readHeader.
-
- n := self onStreamReadBytesInto:inputBytes.
- n == 0 ifTrue:[ self pastEnd ].
- self zinputPosition:n.
!
writeOpenOn:aStream level:level memLevel:memLevel strategy:strategy
@@ -1114,6 +1153,6 @@
!ZipStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.4 2002-06-20 08:57:17 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.5 2002-06-20 11:15:02 ca Exp $'
! !
ZipStream initialize!