Skip to content

Commit 69afb9e

Browse files
committed
Use caret notation for any control characters
1 parent ae35237 commit 69afb9e

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"clue/json-stream": "~0.1.0"
2222
},
2323
"require-dev": {
24-
"clue/tar-react": "~0.1.0"
24+
"clue/tar-react": "~0.1.0",
25+
"clue/caret-notation": "~0.2.0"
2526
}
2627
}

examples/copy.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Clue\React\Docker\Factory;
1010
use Clue\React\Tar\Decoder;
1111
use React\Stream\ReadableStreamInterface;
12+
use Clue\CaretNotation\Encoder;
1213

1314
$container = isset($argv[1]) ? $argv[1] : 'asd';
1415
$file = isset($argv[2]) ? $argv[2] : '/etc/passwd';
@@ -23,11 +24,14 @@
2324

2425
$tar = new Decoder();
2526

26-
$tar->on('entry', function ($header, ReadableStreamInterface $file) {
27+
// use caret notation for any control characters expect \t, \r and \n
28+
$caret = new Encoder("\t\r\n");
29+
30+
$tar->on('entry', function ($header, ReadableStreamInterface $file) use ($caret) {
2731
// write each entry to the console output
28-
echo '########## ' . $header['filename'] . ' ##########' . PHP_EOL;
29-
$file->on('data', function ($chunk) {
30-
echo $chunk;
32+
echo '########## ' . $caret->encode($header['filename']) . ' ##########' . PHP_EOL;
33+
$file->on('data', function ($chunk) use ($caret) {
34+
echo $caret->encode($chunk);
3135
});
3236
});
3337

0 commit comments

Comments
 (0)