crc32

php.internals

Wojtek Meler

21 years ago
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

Wojtek Meler

21 years ago
Oops !!! I've left old license header. Here is smaller clean version that apply to CVS HEAD.

Ron Korving

21 years ago
Wouldn't it be more practical to implement these as stream filters? Ron "Wojtek Meler" <wmeler@wp.pl> schreef in bericht news:431C2738.2040602@wp.pl...
> 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
|
> | license@php.net 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) {

Wojtek Meler

20 years ago
Ron Korving wrote:
> Wouldn't it be more practical to implement these as stream filters?
Sure - I was not aware PHP5 streams - I'm still using PHP4 string.base64 is good choice. But I'm not sure if crc fit to streams. You can always implement fast userland filter with such function ;) . Wojtek

Ron Korving

20 years ago
With a crc function the way you propose it, such a filter could be effectively made in userspace, but you could of course also implement such a filter in the core of php which could do the same trick. Maybe both would be nice. Ron "Wojtek Meler" <wmeler@wp.pl> schreef in bericht news:431D3B3D.3050607@wp.pl...

Sara Golemon

20 years ago
I'd suggest a set of filters as an add-on to the mhash extension: mhash.crc32 mhash.md5 mhash.sha1 mhash.sha256 etc.... -Sara ----- Original Message ----- From: ""Ron Korving"" <r.korving@xit.nl> Newsgroups: php.internals To: <internals@lists.php.net> Sent: Tuesday, September 06, 2005 4:48 AM Subject: Re: crc32

Marcus Börger

20 years ago
Hello Sara, nice and helpfull idea best regards marcus Tuesday, September 6, 2005, 3:57:38 PM, you wrote: