Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fbb65d2

Browse filesBrowse files
authored
Revert "[12.x] Update "Number::fileSize" to use correct prefix and add prefix…" (#55741)
This reverts commit 58ce619.
1 parent df12a08 commit fbb65d2
Copy full SHA for fbb65d2

File tree

Expand file treeCollapse file tree

2 files changed

+16
-41
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-41
lines changed

‎src/Illuminate/Support/Number.php

Copy file name to clipboardExpand all lines: src/Illuminate/Support/Number.php
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,14 @@ public static function currency(int|float $number, string $in = '', ?string $loc
201201
* @param int|float $bytes
202202
* @param int $precision
203203
* @param int|null $maxPrecision
204-
* @param bool $useBinaryPrefix
205204
* @return string
206205
*/
207-
public static function fileSize(int|float $bytes, int $precision = 0, ?int $maxPrecision = null, bool $useBinaryPrefix = false)
206+
public static function fileSize(int|float $bytes, int $precision = 0, ?int $maxPrecision = null)
208207
{
209-
$base = $useBinaryPrefix ? 1024 : 1000;
208+
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
210209

211-
$units = $useBinaryPrefix
212-
? ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB', 'RiB', 'QiB']
213-
: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'RB', 'QB'];
214-
215-
for ($i = 0; ($bytes / $base) > 0.9 && ($i < count($units) - 1); $i++) {
216-
$bytes /= $base;
210+
for ($i = 0; ($bytes / 1024) > 0.9 && ($i < count($units) - 1); $i++) {
211+
$bytes /= 1024;
217212
}
218213

219214
return sprintf('%s %s', static::format($bytes, $precision, $maxPrecision), $units[$i]);

‎tests/Support/SupportNumberTest.php

Copy file name to clipboardExpand all lines: tests/Support/SupportNumberTest.php
+12-32Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -174,38 +174,18 @@ public function testBytesToHuman()
174174
$this->assertSame('0 B', Number::fileSize(0));
175175
$this->assertSame('0.00 B', Number::fileSize(0, precision: 2));
176176
$this->assertSame('1 B', Number::fileSize(1));
177-
$this->assertSame('1 KB', Number::fileSize(1000));
178-
$this->assertSame('2 KB', Number::fileSize(2000));
179-
$this->assertSame('2.00 KB', Number::fileSize(2000, precision: 2));
180-
$this->assertSame('1.23 KB', Number::fileSize(1234, precision: 2));
181-
$this->assertSame('1.234 KB', Number::fileSize(1234, maxPrecision: 3));
182-
$this->assertSame('1.234 KB', Number::fileSize(1234, 3));
183-
$this->assertSame('5 GB', Number::fileSize(1000 * 1000 * 1000 * 5));
184-
$this->assertSame('10 TB', Number::fileSize((1000 ** 4) * 10));
185-
$this->assertSame('10 PB', Number::fileSize((1000 ** 5) * 10));
186-
$this->assertSame('1 ZB', Number::fileSize(1000 ** 7));
187-
$this->assertSame('1 YB', Number::fileSize(1000 ** 8));
188-
$this->assertSame('1 RB', Number::fileSize(1000 ** 9));
189-
$this->assertSame('1 QB', Number::fileSize(1000 ** 10));
190-
$this->assertSame('1,000 QB', Number::fileSize(1000 ** 11));
191-
192-
$this->assertSame('0 B', Number::fileSize(0, useBinaryPrefix: true));
193-
$this->assertSame('0.00 B', Number::fileSize(0, precision: 2, useBinaryPrefix: true));
194-
$this->assertSame('1 B', Number::fileSize(1, useBinaryPrefix: true));
195-
$this->assertSame('1 KiB', Number::fileSize(1024, useBinaryPrefix: true));
196-
$this->assertSame('2 KiB', Number::fileSize(2048, useBinaryPrefix: true));
197-
$this->assertSame('2.00 KiB', Number::fileSize(2048, precision: 2, useBinaryPrefix: true));
198-
$this->assertSame('1.23 KiB', Number::fileSize(1264, precision: 2, useBinaryPrefix: true));
199-
$this->assertSame('1.234 KiB', Number::fileSize(1264.12345, maxPrecision: 3, useBinaryPrefix: true));
200-
$this->assertSame('1.234 KiB', Number::fileSize(1264, 3, useBinaryPrefix: true));
201-
$this->assertSame('5 GiB', Number::fileSize(1024 * 1024 * 1024 * 5, useBinaryPrefix: true));
202-
$this->assertSame('10 TiB', Number::fileSize((1024 ** 4) * 10, useBinaryPrefix: true));
203-
$this->assertSame('10 PiB', Number::fileSize((1024 ** 5) * 10, useBinaryPrefix: true));
204-
$this->assertSame('1 ZiB', Number::fileSize(1024 ** 7, useBinaryPrefix: true));
205-
$this->assertSame('1 YiB', Number::fileSize(1024 ** 8, useBinaryPrefix: true));
206-
$this->assertSame('1 RiB', Number::fileSize(1024 ** 9, useBinaryPrefix: true));
207-
$this->assertSame('1 QiB', Number::fileSize(1024 ** 10, useBinaryPrefix: true));
208-
$this->assertSame('1,024 QiB', Number::fileSize(1024 ** 11, useBinaryPrefix: true));
177+
$this->assertSame('1 KB', Number::fileSize(1024));
178+
$this->assertSame('2 KB', Number::fileSize(2048));
179+
$this->assertSame('2.00 KB', Number::fileSize(2048, precision: 2));
180+
$this->assertSame('1.23 KB', Number::fileSize(1264, precision: 2));
181+
$this->assertSame('1.234 KB', Number::fileSize(1264.12345, maxPrecision: 3));
182+
$this->assertSame('1.234 KB', Number::fileSize(1264, 3));
183+
$this->assertSame('5 GB', Number::fileSize(1024 * 1024 * 1024 * 5));
184+
$this->assertSame('10 TB', Number::fileSize((1024 ** 4) * 10));
185+
$this->assertSame('10 PB', Number::fileSize((1024 ** 5) * 10));
186+
$this->assertSame('1 ZB', Number::fileSize(1024 ** 7));
187+
$this->assertSame('1 YB', Number::fileSize(1024 ** 8));
188+
$this->assertSame('1,024 YB', Number::fileSize(1024 ** 9));
209189
}
210190

211191
public function testClamp()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.