--- a/CompressionStream.st Fri Jul 31 13:22:02 2009 +0200
+++ b/CompressionStream.st Fri Jul 31 14:15:06 2009 +0200
@@ -180,12 +180,11 @@
avail > 0 ifFalse:[^ 0].
count := aCollection size - offset + 1.
-
count < 0 ifTrue:[
- self zerror:'invalid arguments'
+ self zerror:'invalid arguments'
].
count == 0 ifTrue:[
- ^ 0
+ ^ 0
].
count := avail min:count.
@@ -194,33 +193,31 @@
start := position.
position := position + count.
-%{ unsigned char * _dstPt;
+%{
+ unsigned char * _dstPt;
+ int _count = __intVal( count );
+ int _offset = __intVal( offset );
+ unsigned char * _srcPt;
+ OBJ _srcObj = __INST( outputBytes );
if( __isBytes(aCollection) ) {
- _dstPt = (unsigned char *) (__ByteArrayInstPtr(aCollection)->ba_element);
+ _dstPt = (unsigned char *) (__byteArrayVal(aCollection));
} else if (__isString(aCollection)) {
- _dstPt = (unsigned char *) (__stringVal( aCollection));
- } else
- _dstPt = (unsigned char *) 0;
+ _dstPt = (unsigned char *) (__stringVal( aCollection));
+ } else {
+ goto error;
+ }
- if( _dstPt )
- {
- int _loop, _count, _offset;
- unsigned char * _srcPt;
- OBJ _srcObj = __INST( outputBytes );
+ _dstPt = _dstPt + _offset - 1;
- _offset = __intVal( offset );
- _dstPt = _dstPt + _offset - 1;
+ _srcPt = (unsigned char *) __externalBytesAddress( _srcObj );
+ _srcPt += __intVal( start );
- _srcPt = (unsigned char *) __externalBytesAddress( _srcObj );
- _srcPt += __intVal( start );
- _count = __intVal( count );
+ memcpy(_dstPt, _srcPt, _count);
- for( _loop = 0; _loop < _count; ++_loop )
- * _dstPt++ = * _srcPt++;
+ RETURN(__MKSMALLINT(_count));
- RETURN(__MKSMALLINT(_count));
- }
+error: ;
%}.
^ self zerror:'invalid argument'
@@ -317,32 +314,32 @@
!
canReadWithoutBlocking
- "returns true if data are available for reading;
+ "returns true if data is available for reading;
false if the stream is at end.
- updates the readLimit and position"
+ Updates the readLimit and position"
|n|
mode == #readonly ifFalse:[
- self errorWriteOnly
+ self errorWriteOnly
].
hitEOF == true ifTrue:[^ false].
position >= readLimit ifTrue:[
- [(readLimit := self zinflate) == 0] whileTrue:[
- n := onStream nextBytes:(inputBytes size) into:inputBytes startingAt:1.
+ [(readLimit := self zinflate) == 0] whileTrue:[
+ n := onStream nextBytes:(inputBytes size) into:inputBytes startingAt:1.
- n == 0 ifTrue:[
- hitEOF := true.
- ^ false
- ].
- self zset_avail_in:n.
- ].
- readLimit isNil ifTrue:[
- hitEOF := true.
- ^ false
- ].
- position := 0.
+ n == 0 ifTrue:[
+ hitEOF := true.
+ ^ false
+ ].
+ self zset_avail_in:n.
+ ].
+ readLimit isNil ifTrue:[
+ hitEOF := true.
+ ^ false
+ ].
+ position := 0.
].
^ true
!
@@ -446,7 +443,7 @@
"read the next n elements of the stream into aBuffer.
Return the number of bytes read."
- |data count remaining offset|
+ |count remaining offset|
self canReadWithoutBlocking ifFalse:[
^ 0
@@ -455,7 +452,7 @@
remaining := n.
[self canReadWithoutBlocking] whileTrue:[
- count := self z_nextAvailableInto:data startingAt:offset maxCount:remaining.
+ count := self z_nextAvailableInto:aBuffer startingAt:offset maxCount:remaining.
offset := count + offset.
remaining := remaining - count.
remaining == 0 ifTrue:[^ n]
@@ -593,7 +590,7 @@
!CompressionStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/CompressionStream.st,v 1.24 2009-07-31 11:22:02 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/CompressionStream.st,v 1.25 2009-07-31 12:15:06 cg Exp $'
! !
CompressionStream initialize!