ZipStream.st
changeset 2175 f66d96d2c015
parent 2019 4a33a6715a51
child 2177 875e7abd9620
--- a/ZipStream.st	Tue Jun 30 15:27:51 2009 +0200
+++ b/ZipStream.st	Tue Jun 30 17:28:52 2009 +0200
@@ -245,6 +245,32 @@
 
 !ZipStream class methodsFor:'ZipInterface compatibility - crc'!
 
+crc32Add:aCharacterOrByte crc:crc
+    "Update a running crc waCharacterOrByte
+     and return the updated crc "
+%{
+    if( (__isInteger(crc)))     {
+        char __byte;
+        uLong  __crc;
+
+        if (__isCharacter(aCharacterOrByte)) {
+            __byte = __characterVal(aCharacterOrByte);
+        } else if (__isSmallInteger(aCharacterOrByte)) {
+            __byte = __intVal(aCharacterOrByte);
+        } else{
+            goto err;
+        }
+
+        __crc  = __longIntVal( crc );
+        __crc = crc32(__crc, (Byte *) &__byte, 1 );
+        RETURN( __MKUINT(__crc) );
+    }
+err:;
+%}.
+
+    ^ self error:'invalid argument'
+!
+
 crc32BytesIn:bytesIn
     "compute crc with the bytes buf[1.. bytesIn size]
      and return the crc
@@ -282,42 +308,38 @@
 
 crc32BytesIn:bytesIn from:start to:stop crc:crc
     "Update a running crc with the bytes buf[start.. stop]
-     and return the updated
-    "
-    |size|
-
-     size := stop - start + 1.
+     and return the updated crc"
 
-     (    (start between:1 and:stop)
-      and:[size > 0
-      and:[bytesIn size >= stop]]
-     ) ifFalse:[
-	^ self error:'invalid argument size'
-    ].
 %{
-    if( (__isInteger(crc)) && (__isSmallInteger(start)) && (__isSmallInteger(size)) )
-    {
-	char * __bytes  = 0;
+    if (__isInteger(crc) && __isSmallInteger(start) && __isSmallInteger(stop)) {
+        char * __bytes  = 0;
+        unsigned int __size;
 
-	if (__isBytes(bytesIn)) {
-	    __bytes = __ByteArrayInstPtr(bytesIn)->ba_element;
-	} else {
-	    if (__isString(bytesIn)) {
-		__bytes = __stringVal( bytesIn );
-	    }
-	}
+        if (__isBytes(bytesIn)) {
+            __bytes = __byteArrayVal(bytesIn);
+            __size = __byteArraySize(bytesIn);
+        } else if (__isString(bytesIn)) {
+            __bytes = __stringVal(bytesIn);
+            __size = __stringSize(bytesIn);
+        } else {
+            goto err;
+        }
 
-	if( __bytes )
-	{
-	    uLong  __crc  = __longIntVal( crc );
-	    uInt   __size = __intVal( size );
+        uLong  __crc  = __longIntVal( crc );
+        uInt   __start = __intVal( start );
+        uInt   __stop = __intVal( stop );
+
+        if (__start < 1 || __start > __size) goto err;
+        if (__stop < 1 || __stop > __size) goto err;
 
-	    __bytes += (__intVal( start)) - 1;
-	    __crc = crc32(__crc, (Byte *) __bytes, __size );
+        __size = __stop - __start + 1;
 
-	    RETURN( __MKUINT(__crc) );
-	}
+        __bytes += __start - 1;
+        __crc = crc32(__crc, (Byte *) __bytes, __size );
+
+        RETURN( __MKUINT(__crc) );
     }
+err:;
 %}.
 
     ^ self error:'invalid argument size'
@@ -752,7 +774,7 @@
 !ZipStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.30 2008-06-30 09:07:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.31 2009-06-30 15:28:52 stefan Exp $'
 ! !
 
 ZipStream initialize!