I've patched original crc32 PHP function to allow incremental crc32 counting.
It touches only a few lines of original code.
New crc32 function signature is

   int crc32(string str [,int prev_sum])

With this patch you can generate crc32 checksum for even large files without reading it contents to single variable.
Fe. instead of doing

|   $file_string = file_get_contents($file);
$crc = crc32($file_string); |
you can do

   $crc=0;
   $f =fopen($file,'r');
   while ( $data=fread($f,1024)) $crc = crc32($data,$crc);
   fclose($f);

Icremental processing has less memory requirements.
I'd like also change base64_* functions to allow incremental processing.

Any chances apply such changes ?

Regards,
Wojtek
Index: crc32.c
===================================================================
RCS file: /repository/php-src/ext/standard/crc32.c,v
retrieving revision 1.16
diff -u -r1.16 crc32.c
--- crc32.c	3 Aug 2005 14:07:57 -0000	1.16
+++ crc32.c	5 Sep 2005 11:02:00 -0000
@@ -1,13 +1,13 @@
 /*
    +----------------------------------------------------------------------+
-   | PHP Version 5                                                        |
+   | PHP Version 4                                                        |
    +----------------------------------------------------------------------+
-   | Copyright (c) 1997-2005 The PHP Group                                |
+   | Copyright (c) 1997-2003 The PHP Group                                |
    +----------------------------------------------------------------------+
-   | This source file is subject to version 3.0 of the PHP license,       |
+   | This source file is subject to version 2.02 of the PHP license,      |
    | that is bundled with this package in the file LICENSE, and is        |
-   | available through the world-wide-web at the following url:           |
-   | http://www.php.net/license/3_0.txt.                                  |
+   | available at through the world-wide-web at                           |
+   | http://www.php.net/license/2_02.txt.                                 |
    | If you did not receive a copy of the PHP license and are unable to   |
    | obtain it through the world-wide-web, please send a note to          |
    | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
@@ -22,20 +22,19 @@
 #include "basic_functions.h"
 #include "crc32.h"
 
-/* {{{ proto string crc32(string str)
+/* {{{ proto int crc32(string str[,int prev_crc])
    Calculate the crc32 polynomial of a string */
 PHP_NAMED_FUNCTION(php_if_crc32)
 {
-	unsigned int crc = ~0;
+	unsigned int crc = 0;
 	char *p;
-	int len, nr;
+	int len;
 	
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &p, &len, &crc) == FAILURE) {
 		return;
 	}
-
-	len = 0 ;
-	for (len += nr; nr--; ++p) {
+	crc = ~crc;
+	for (; len--; ++p) {
 	    CRC32(crc, *p);
 	}
 	RETVAL_LONG(~crc);

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to