Example: Stdout
Topic: Filesystem
Description
Stdout is a special type of filesystem allowing to
write straight to stdout of the process.
Stdout is a write-only filesystem. It is not possible to read from it.
Its main purpose is to allow web servers to stream data to the client without buffering it in memory.
composer.json
{
"name": "flow-php/examples",
"description": "Flow PHP - Examples",
"license": "MIT",
"type": "library",
"require": {
"flow-php/etl": "1.x-dev"
}
}
code.php
<?php
declare(strict_types=1);
use function Flow\Filesystem\DSL\{fstab, path, protocol};
require __DIR__ . '/vendor/autoload.php';
$outputStream = fstab()->for(protocol('stdout'))->writeTo(path('stdout://'));
$outputStream->append("Files List\n\n");
foreach (fstab()->for(protocol('file'))->list(path(__DIR__ . '/*')) as $file) {
$outputStream->append(($file->isFile() ? 'File' : 'Directory') . ': ' . $file->path->basename() . "\n");
}
$outputStream->close();