Req #53709 [Opn->Wfx]: [feat] md5_file and sha1_file should accept an additional length
| From: | aharvey@php.net | Date: | Wed, 12 Jan 2011 03:34:22 +0000 |
| Subject: | Req #53709 [Opn->Wfx]: [feat] md5_file and sha1_file should accept an additional length | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157833@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53709&edit=1
ID: 53709
Updated by: aharvey@php.net
Reported by: jthijssen at noxlogic dot nl
Summary: [feat] md5_file and sha1_file should accept an
additional length
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Strings related
+Package: hash related
Operating System: NA
PHP Version: 5.3SVN-2011-01-10 (SVN)
Block user comment: N
Private report: N
New Comment:
This seems like a bit too much of a corner case to me to justify
muddying the API with optional parameters, given that this
functionality could be replicated in userspace with a four line
function that called fopen() and fread() (or, alternatively, fopen()
and hash_update_stream()).
Beyond that, even if this were to be accepted, hash_file() would also
need the same treatment.
Given that, traditionally, feature requests that are trivial to
replicate in userspace aren't implemented, I'm closing this won't fix.
Previous Comments:
------------------------------------------------------------------------
[2011-01-10 22:18:27] jthijssen at noxlogic dot nl
I've added the patch in a base64 format because of a bug in the php
bugtracker (bug #53703).
------------------------------------------------------------------------
[2011-01-10 22:11:44] jthijssen at noxlogic dot nl
Description:
------------
Sometimes you want to have the md5() or sha1() from a file, but not the
whole file. This is particularly handy when you want to sync directories
and you don't want to md5 whole files but just the first 4096 or 8192
bytes to speed up the checking.
This patch implements an additional parameter to md5_file() and
sha1_file() where you can add the number of bytes that needs to be
read/md5()'d from the source file.
Test script:
---------------
Returns the md5 from the first 8192 bytes from the iso-file:
md5_file('dvdimage.iso', false, 8192);
Returns the md5 from the complete file, even though length is way larger
than the file:
md5_file('dvdimage.iso', false, 81920000000);
Expected result:
----------------
The md5_file() and sha1_file() functions actually accepting the
additional parameter.
Actual result:
--------------
Currently, it does not accept a 3rd paramter. The patch adds the
additional parameter (which defaults to -1, which means to read the
complete file).
Additionally added and fixed tests in md5_file.phpt and sha1_file.phpt
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53709&edit=1