php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53709 [feat] md5_file and sha1_file should accept an additional length
Submitted: 2011-01-10 22:11 UTC Modified: 2011-01-12 04:34 UTC
From: jthijssen at noxlogic dot nl Assigned:
Status: Wont fix Package: hash related
PHP Version: 5.3SVN-2011-01-10 (SVN) OS: NA
Private report: No CVE-ID: None
 [2011-01-10 22:11 UTC] 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

Patches

md5sha1_file.diff.base64 (last revision 2011-01-10 21:17 UTC by jthijssen at noxlogic dot nl)
md5sha1_file.diff (last revision 2011-01-10 21:14 UTC by jthijssen at noxlogic dot nl)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-10 22:18 UTC] 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-12 04:34 UTC] aharvey@php.net
-Status: Open +Status: Wont fix -Package: Strings related +Package: hash related
 [2011-01-12 04:34 UTC] aharvey@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC