Re: Idea for a new extensions: checksum_from_file()

From: Date: Sun, 24 Jun 2007 09:45:23 +0000
Subject: Re: Idea for a new extensions: checksum_from_file()
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-4739@lists.php.net to get a copy of this message
Hi Andreas, since PHP 5.2.1 PHP bundles the hash extension, see php.net/hash which includes way more hashing algorithms (see hash_algos()) and a hash_file() function and should full-fill all your needs. johannes On Sun, 2007-06-24 at 02:16 -0700, ecc wrote: > Hi, > > there are 3 checksums supported in php. (md5, crc32 and sha1, Mabye there > are more...) > > md5 and sha1 allready have an *_file function available, crc32 dont have > them. crc32 dont have this function in the latest php version. > > These *_file functions are usefull in the most cases, but have a very big > disadvantage. They could not handle header offsets. > > Theses header offsets arent trivial, because e.g. MP3 files also contains an > header. (In this case, its not really an header, because its an offset at > the end of the MP3 file containing the meta-informations ID3). So if you > parse the checksum of an MP3, you allway get the wrong checksum, because the > song is the same in the most cases, but only the meta-infos are changed. > This isnt the best example, but it shows you the problem. > > This is my implementation idea (pseudocode). > > // get crc32 and md5 checksums from $file, begin at byte 512 and stop 128 > bytes before fileend. > // call method "updateProcess" everytime if 1024 bytes for file are > processed! (eg. for php-gtk2) > checksum_from_file($file, array('crc32', 'md5'), 512, -128, array($this, > 'updateProcess', 1024)); > > public function checksum_from_file($file= false, $checksum_type = false, > $start_offset=false, $end_offset=false, $callback = false) { > $checksums = array(); > // get data > return $checksums; > } > > $file should be contain a filename, a filehandle or and something like this > z:/test.zip#filename.php > So the creation of temp-copys of e.g. zip content could be transparent done > without managing this externaly. > > This extension have to parse files bigger than 600 MB. So, the funktion have > to be ready for this. (file_get_contents crash in this cases :-)) > > Now, i have to read the complete filecontent to the memory using a php > buildin function and create an checksum by this string, because i´ve had to > manage the header offsets. Not really performant, and very very slow for > large files > 64 MB > > Regards, > Andreas > http://www.php-gtk.eu/apps/emucontrolcenter > > Here an overview of the allready implemented checksum function in php. > > string md5_file ( string $filename [, bool $raw_output] ) > http://de2.php.net/manual/de/function.md5-file.php > > string sha1_file ( string $filename [, bool $raw_output] ) > http://de2.php.net/manual/de/function.sha1-file.php > > int crc32 ( string $str ) > http://de2.php.net/manual/de/function.crc32.php

« previous php.pecl.dev (#4739) next »