Skip to content

Commit 7d47478

Browse files
committed
feat: display filesize
1 parent 053160f commit 7d47478

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/DumbDbCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ACPL\FlarumDbDumper;
44

5+
use ACPL\FlarumDbDumper\Helper\Format;
56
use Carbon\Carbon;
67
use Exception;
78
use Flarum\Console\AbstractCommand;
@@ -248,7 +249,8 @@ protected function fire(): int
248249

249250
try {
250251
$dumper->dumpToFile($path);
251-
$this->info("Database dumped successfully to: $path");
252+
$filesize = Format::humanReadableSize(filesize($path));
253+
$this->info("Database dumped successfully to: $path ($filesize)");
252254
} catch (Exception $e) {
253255
$this->error('Failed to dump database: '.$e->getMessage());
254256

src/Helper/Format.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace ACPL\FlarumDbDumper\Helper;
4+
5+
class Format
6+
{
7+
public static function humanReadableSize(int $sizeInBytes): string
8+
{
9+
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
10+
$i = $sizeInBytes ? floor(log($sizeInBytes, 1024)) : 1;
11+
12+
return round($sizeInBytes / pow(1024, $i), 2).' '.$units[$i];
13+
}
14+
}

0 commit comments

Comments
 (0)