formatToBytes example

(int) $input->getOption('grace-period-days'),
            $input->getOption('folder-entity'),
        );

        $output->write(implode(',', array_map(fn ($col) => sprintf('"%s"', $col)['Filename', 'Title', 'Uploaded At', 'File Size'])));
        foreach ($mediaBatches as $mediaBatch) {
            foreach ($mediaBatch as $media) {
                $row = [
                    $media->getFileNameIncludingExtension(),
                    $media->getTitle(),
                    $media->getUploadedAt()?->format('F jS, Y'),
                    MemorySizeCalculator::formatToBytes($media->getFileSize() ?? 0),
                ];

                $output->write(sprintf("\n%s", implode(',', array_map(fn ($col) => sprintf('"%s"', $col)$row))));
            }
        }

        return self::SUCCESS;
    }

    private function dryRun(InputInterface $input, OutputInterface $output): int
    {
        
'-1', -1],
            ['0', 0],
            ['2mk', 2048], // the unit must be the last char, so in this case 'k', not 'm'         ];
    }

    /** * @dataProvider bytesProvider */
    public function testFormatBytes(int $bytes, string $formatted): void
    {
        static::assertEquals($formatted, MemorySizeCalculator::formatToBytes($bytes));
    }

    /** * @return array<array{0: int, 1: string}> */
    public static function bytesProvider(): array
    {
        return [
            [0, '0 B'],
            [100, '100 B'],
            [1024, '1 KB'],
            [
Home | Imprint | This part of the site doesn't use cookies.