Skip to content
Search
Examples

Filesystem

Description

Write data directly to the process stdout. This is useful for streaming data to web clients without buffering in memory.

Note: Stdout is write-only-reading is not supported.

Documentation

Every reader and writer reaches storage through the filesystem abstraction.

Code

<?php

declare(strict_types=1);

use function Flow\Filesystem\DSL\{fstab, path};

require __DIR__ . '/vendor/autoload.php';

$filesystem = fstab()->for('file');

foreach (['first.txt' => "one\n", 'second.txt' => "two\n"] as $name => $content) {
    $stream = $filesystem->writeTo(path(__DIR__ . '/listing/' . $name));
    $stream->append($content);
    $stream->close();
}

$outputStream = fstab()->for('stdout')->writeTo(path('stdout://'));

$outputStream->append("Files List\n\n");

foreach ($filesystem->list(path(__DIR__ . '/listing/*.txt')) as $file) {
    $outputStream->append(($file->isFile() ? 'File' : 'Directory') . ': ' . $file->path->basename() . "\n");
}

$outputStream->close();
Contributors

Built in the open.

Join us on GitHub
scroll back to top