PHP code example of sblazheev / filesystem
1. Go to this page and download the library: Download sblazheev/filesystem library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sblazheev / filesystem example snippets
$loop = \React\EventLoop\Factory::create();
$filesystem = \React\Filesystem\Filesystem::create($loop);
$loop = \React\EventLoop\Factory::create();
$filesystem = \React\Filesystem\Filesystem::create($loop);
$file = $filesystem->file(__FILE__); // Returns a \React\Filesystem\Node\FileInterface compatible object
$filesystem->getContents('test.txt')->then(function($contents) {
});
$filesystem->file('test.txt')->open('r')->then(function($stream) {
return \React\Stream\BufferedSink::createPromise($stream);
})->then(function($contents) {
// ...
});
$filesystem->file('test.txt')->open('r')->then(function ($stream) use ($node) {
$buffer = '';
$deferred = new \React\Promise\Deferred();
$stream->on('data', function ($data) use (&$buffer) {
$buffer += $data;
});
$stream->on('end', function ($data) use ($stream, $deferred, &$buffer) {
$stream->close();
$deferred->resolve(&$buffer);
});
return $deferred->promise();
});
$filesystem->file('test.txt')->open('cwt')->then(function ($stream) {
$stream->write('a');
$stream->write('b');
$stream->write('c');
$stream->write('d');
$stream->end('e');
});
$loop = \React\EventLoop\Factory::create();
$filesystem = \React\Filesystem\Filesystem::create($loop);
$dir = $filesystem->dir(__DIR__); // Returns a \React\Filesystem\Node\DirectoryInterface compatible object
$filesystem->dir(__DIR__)->ls()->then(function (array $list) {
foreach ($list as $node) {
echo $node->getPath(), PHP_EOL;
}
});