ZipStream.st
changeset 2335 609923563c1d
parent 2196 9eecfefd08aa
child 2488 702fc73e1b3c
equal deleted inserted replaced
2334:1a245a5b81ab 2335:609923563c1d
   200      (    (start between:1 and:stop)
   200      (    (start between:1 and:stop)
   201       and:[size > 0
   201       and:[size > 0
   202       and:[bytesIn  size >= stop
   202       and:[bytesIn  size >= stop
   203       and:[bytesOut size >  0]]]
   203       and:[bytesOut size >  0]]]
   204      ) ifFalse:[
   204      ) ifFalse:[
   205 	^ self error:'invalid argument size'
   205         ^ self error:'invalid argument size'
   206     ].
   206     ].
   207 
   207 
   208 %{
   208 %{
   209     char *  __bytesIn  = 0;
   209     char *  __bytesIn  = 0;
   210     uLong   __countIn  = 0;
   210     uLong   __countIn  = 0;
   211     char *  __bytesOut = 0;
   211     char *  __bytesOut = 0;
   212     uLong   __countOut = 0;
   212     uLong   __countOut = 0;
   213 
   213 
   214     if( (__isSmallInteger(start)) && (__isSmallInteger(stop)) && (__isSmallInteger(size)) )
   214     if( (__isSmallInteger(start)) && (__isSmallInteger(stop)) && (__isSmallInteger(size)) )
   215     {
   215     {
   216 	__countIn = __intVal( size );
   216         __countIn = __intVal( size );
   217 
   217 
   218 	if (__isBytes(bytesIn)) {
   218         if (__isBytes(bytesIn)) {
   219 	    __bytesIn = __ByteArrayInstPtr(bytesIn)->ba_element;
   219             __bytesIn = __ByteArrayInstPtr(bytesIn)->ba_element;
   220 	} else {
   220         } else {
   221 	    if (__isString(bytesIn)) {
   221             if (__isStringLike(bytesIn)) {
   222 		__bytesIn = __stringVal( bytesIn );
   222                 __bytesIn = __stringVal( bytesIn );
   223 	    }
   223             }
   224 	}
   224         }
   225 
   225 
   226 	if (__isBytes(bytesOut)) {
   226         if (__isBytes(bytesOut)) {
   227 	    __bytesOut = __ByteArrayInstPtr(bytesOut)->ba_element;
   227             __bytesOut = __ByteArrayInstPtr(bytesOut)->ba_element;
   228 	    __countOut = __byteArraySize( bytesOut );
   228             __countOut = __byteArraySize( bytesOut );
   229 	} else {
   229         } else {
   230 	    if (__isString(bytesOut)) {
   230             if (__isString(bytesOut)) {
   231 		__bytesOut = __stringVal( bytesOut );
   231                 __bytesOut = __stringVal( bytesOut );
   232 		__countOut = __stringSize( bytesOut );
   232                 __countOut = __stringSize( bytesOut );
   233 	    }
   233             }
   234 	}
   234         }
   235     }
   235     }
   236 
   236 
   237     if( __bytesOut && __bytesIn )
   237     if( __bytesOut && __bytesIn )
   238     {
   238     {
   239 	int __result = Z_OK;
   239         int __result = Z_OK;
   240 
   240 
   241 	__bytesIn += (__intVal( start)) - 1;
   241         __bytesIn += (__intVal( start)) - 1;
   242 
   242 
   243 	if( doCompress == true )
   243         if( doCompress == true )
   244 	    __result   = compress  ( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn );
   244             __result   = compress  ( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn );
   245 	else
   245         else
   246 	    __result   = uncompress( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn );
   246             __result   = uncompress( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn );
   247 
   247 
   248 	if( __result == Z_OK )
   248         if( __result == Z_OK )
   249 	    { RETURN(__MKSMALLINT(__countOut)); }
   249             { RETURN(__MKSMALLINT(__countOut)); }
   250 
   250 
   251 	errorNr = __MKSMALLINT( __result );
   251         errorNr = __MKSMALLINT( __result );
   252     }
   252     }
   253 %}.
   253 %}.
   254 
   254 
   255     errorNr isNil ifTrue:[ ^ self error:'invalid arguments' ].
   255     errorNr isNil ifTrue:[ ^ self error:'invalid arguments' ].
   256     errorNr ==  1 ifTrue:[ ^ self error:'stream at end' ].
   256     errorNr ==  1 ifTrue:[ ^ self error:'stream at end' ].
   336     "Update a running crc with the bytes buf[start.. stop]
   336     "Update a running crc with the bytes buf[start.. stop]
   337      and return the updated crc"
   337      and return the updated crc"
   338 
   338 
   339 %{
   339 %{
   340     if (__isInteger(crc) && __isSmallInteger(start) && __isSmallInteger(stop)) {
   340     if (__isInteger(crc) && __isSmallInteger(start) && __isSmallInteger(stop)) {
   341 	char * __bytes  = 0;
   341         char * __bytes  = 0;
   342 	unsigned int __size;
   342         unsigned int __size;
   343 	uLong  __crc  = __unsignedLongIntVal( crc );
   343         uLong  __crc  = __unsignedLongIntVal( crc );
   344 	uInt   __start = __intVal( start );
   344         uInt   __start = __intVal( start );
   345 	uInt   __stop = __intVal( stop );
   345         uInt   __stop = __intVal( stop );
   346 
   346 
   347 	if (__isBytes(bytesIn)) {
   347         if (__isBytes(bytesIn)) {
   348 	    __bytes = __byteArrayVal(bytesIn);
   348             __bytes = __byteArrayVal(bytesIn);
   349 	    __size = __byteArraySize(bytesIn);
   349             __size = __byteArraySize(bytesIn);
   350 	} else if (__isString(bytesIn)) {
   350         } else if (__isStringLike(bytesIn)) {
   351 	    __bytes = __stringVal(bytesIn);
   351             __bytes = __stringVal(bytesIn);
   352 	    __size = __stringSize(bytesIn);
   352             __size = __stringSize(bytesIn);
   353 	} else {
   353         } else {
   354 	    goto err;
   354             goto err;
   355 	}
   355         }
   356 
   356 
   357 
   357 
   358 	if (__start < 1 || __start > __size) goto err;
   358         if (__start < 1 || __start > __size) goto err;
   359 	if (__stop < 1 || __stop > __size) goto err;
   359         if (__stop < 1 || __stop > __size) goto err;
   360 
   360 
   361 	__size = __stop - __start + 1;
   361         __size = __stop - __start + 1;
   362 
   362 
   363 	__bytes += __start - 1;
   363         __bytes += __start - 1;
   364 	__crc = crc32(__crc, (Byte *) __bytes, __size );
   364         __crc = crc32(__crc, (Byte *) __bytes, __size );
   365 
   365 
   366 	RETURN( __MKUINT(__crc) );
   366         RETURN( __MKUINT(__crc) );
   367     }
   367     }
   368 err:;
   368 err:;
   369 %}.
   369 %}.
   370 
   370 
   371     ^ self error:'invalid argument size'
   371     ^ self error:'invalid argument size'
   822 ! !
   822 ! !
   823 
   823 
   824 !ZipStream class methodsFor:'documentation'!
   824 !ZipStream class methodsFor:'documentation'!
   825 
   825 
   826 version
   826 version
   827     ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.36 2009-08-03 13:38:33 ca Exp $'
   827     ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.37 2009-11-05 16:25:23 stefan Exp $'
       
   828 !
       
   829 
       
   830 version_CVS
       
   831     ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.37 2009-11-05 16:25:23 stefan Exp $'
   828 ! !
   832 ! !
   829 
   833 
   830 ZipStream initialize!
   834 ZipStream initialize!