Skip to content
This repository was archived by the owner on Jun 2, 2019. It is now read-only.

Commit 62f4de7

Browse files
authored
Merge pull request #2 from paulijar/master
Fixed parsing of non-regular files
2 parents 89c8a68 + 382c015 commit 62f4de7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/getID3/getid3_handler.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ protected function fread($bytes) {
8484
if (!getid3_lib::intValueSupported($pos)) {
8585
throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10);
8686
}
87-
return fread($this->getid3->fp, $bytes);
87+
88+
// System fread function may return less data than requested in case the file is not a regular local file.
89+
// See http://php.net/manual/en/function.fread.php. Call it repeatedly in a loop if that is the case.
90+
$contents = '';
91+
do {
92+
$part = fread($this->getid3->fp, $bytes);
93+
$partLength = strlen($part);
94+
$bytes -= $partLength;
95+
$contents .= $part;
96+
} while ($bytes > 0 && $partLength > 0);
97+
return $contents;
8898
}
8999

90100
protected function fseek($bytes, $whence=SEEK_SET) {

0 commit comments

Comments
 (0)