aboutsummaryrefslogtreecommitdiff
path: root/zipstream.php
diff options
context:
space:
mode:
authorpabs <pabs@pablotron.org>2007-09-20 23:46:01 -0400
committerpabs <pabs@pablotron.org>2007-09-20 23:46:01 -0400
commit86a515ea891675214769419835b196a0cbb14442 (patch)
tree318ca61c5216b47d8a3dd95ad3b9b8783b2d8d70 /zipstream.php
parent7bd75d7b9acab8b31443361c5d2a67a19cd41c26 (diff)
downloadzipstream-php-86a515ea891675214769419835b196a0cbb14442.tar.bz2
zipstream-php-86a515ea891675214769419835b196a0cbb14442.zip
Fix crc32 calculation.
Diffstat (limited to 'zipstream.php')
-rw-r--r--zipstream.php9
1 files changed, 6 insertions, 3 deletions
diff --git a/zipstream.php b/zipstream.php
index 5b8965f..1fe72dd 100644
--- a/zipstream.php
+++ b/zipstream.php
@@ -319,6 +319,7 @@ class ZipStream {
function add_large_file($name, $path, $opt = array()) {
$st = stat($path);
$block_size = 1048576; # process in 1 megabyte chunks
+ $algo = 'crc32b';
# calculate header attributes
$zlen = $len = $st['size'];
@@ -327,14 +328,15 @@ class ZipStream {
if ($meth_str == 'store') {
# store method
$meth = 0x00;
- $crc = hash_file('crc32', $path);
+ $crc = unpack('V', hash_file($algo, $path, true));
+ $crc = $crc[1];
} elseif ($meth_str == 'deflate') {
# deflate method
$meth = 0x08;
# open file, calculate crc and compressed file length
$fh = fopen($path, 'rb');
- $hash_ctx = hash_init('crc32');
+ $hash_ctx = hash_init($algo);
$zlen = 0;
# read each block, update crc and zlen
@@ -346,7 +348,8 @@ class ZipStream {
# close file and finalize crc
fclose($fh);
- $crc = hash_final($hash_ctx);
+ $crc = unpack('V', hash_final($hash_ctx, true));
+ $crc = $crc[1];
} else {
die("unknown large_file_method: $meth_str");
}