forked from clue/reactphp-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.php
More file actions
32 lines (22 loc) · 975 Bytes
/
export.php
File metadata and controls
32 lines (22 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
// this example shows how the containerExport() call returns a TAR stream
// and how we it can be piped into a output tar file.
use Clue\React\Docker\Client;
use React\Stream\WritableResourceStream;
require __DIR__ . '/../vendor/autoload.php';
if (DIRECTORY_SEPARATOR === '\\') {
exit('File I/O not supported on Windows' . PHP_EOL);
}
$container = isset($argv[1]) ? $argv[1] : 'asd';
$target = isset($argv[2]) ? $argv[2] : ($container . '.tar');
echo 'Exporting whole container "' . $container . '" to "' . $target .'" (pass as arguments to this example)' . PHP_EOL;
$loop = React\EventLoop\Factory::create();
$client = new Client($loop);
$stream = $client->containerExportStream($container);
$stream->on('error', function ($e = null) {
// will be called if the container is invalid/does not exist
echo 'ERROR requesting stream' . PHP_EOL . $e;
});
$out = new WritableResourceStream(fopen($target, 'w'), $loop);
$stream->pipe($out);
$loop->run();