Add filesize fallback for large files and 32bit PHP.

This commit is contained in:
Lars Jung 2014-07-09 02:40:23 +02:00
parent d33b0156fc
commit f9e7e5f9c2
2 changed files with 29 additions and 3 deletions

View file

@ -4,12 +4,12 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
var decimalMetric = { var decimalMetric = {
t: 1000.0, t: 1000.0,
k: 1000.0, k: 1000.0,
u: ['B', 'KB', 'MB', 'GB', 'TB'] u: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
}, },
binaryMetric = { binaryMetric = {
t: 1024.0, t: 1024.0,
k: 1024.0, k: 1024.0,
u: ['B', 'KiB', 'MiB', 'GiB', 'TiB'] u: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
}, },
defaultMetric = decimalMetric, defaultMetric = decimalMetric,
defaultDateFormat = 'YYYY-MM-DD HH:mm', defaultDateFormat = 'YYYY-MM-DD HH:mm',

View file

@ -28,7 +28,33 @@ class Item {
if (is_file($path)) { if (is_file($path)) {
$size = @filesize($path); if (PHP_INT_SIZE < 8) {
$_handle = fopen($path, "r");
$_pos = 0;
$_size = 1073741824;
fseek($_handle, 0, SEEK_SET);
while ($_size > 1) {
fseek($_handle, $_size, SEEK_CUR);
if (fgetc($_handle) === false) {
fseek($_handle, -$_size, SEEK_CUR);
$_size = (int)($_size / 2);
} else {
fseek($_handle, -1, SEEK_CUR);
$_pos += $_size;
}
}
while (fgetc($_handle) !== false) {
$_pos++;
}
fclose($_handle);
$size = $_pos * 1e20;
} else {
$size = @filesize($path);
}
} else if (is_dir($path)) { } else if (is_dir($path)) {