Skip to content

Commit bf648ed

Browse files
committed
Initial import
0 parents  commit bf648ed

13 files changed

Lines changed: 636 additions & 0 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
/composer.lock

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: php
2+
php:
3+
- 5.3
4+
- 5.6
5+
- hhvm
6+
install:
7+
- composer install --prefer-source --no-interaction
8+
script:
9+
- phpunit --coverage-text

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Christian Lück
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is furnished
10+
to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# clue/tar-react [![Build Status](https://travis-ci.org/clue/php-tar-react.svg?branch=master)](https://travis-ci.org/clue/php-tar-react)
2+
3+
Async, streaming parser for the [TAR file format](https://en.wikipedia.org/wiki/Tar_%28computing%29) (Tape ARchive),
4+
built on top of [React PHP](http://reactphp.org/).
5+
6+
Implements UStar (Uniform Standard Tape ARchive) format, introduced by the POSIX IEEE P1003.1
7+
8+
> Note: This project is in early alpha stage! Feel free to report any issues you encounter.
9+
10+
## Quickstart example
11+
12+
Once [installed](#install), you can use the following code to pipe a readable
13+
tar stream into the `Decoder` which emits "entry" events for each individual file:
14+
15+
```php
16+
$loop = React\EventLoop\Factory::create();
17+
$stream = new Stream(fopen('archive.tar', 'r'), $loop);
18+
19+
$decoder = new Decoder();
20+
21+
$decoder->on('entry', function ($header, ReadableStreamInterface $file) {
22+
echo 'File ' . $header['filename'] . '
23+
echo $header['size'] . ' bytes:' . PHP_EOL;
24+
25+
$file->on('data', function ($chunk) {
26+
echo $chunk;
27+
});
28+
});
29+
30+
$stream->pipe($decoder);
31+
32+
$loop->run();
33+
```
34+
35+
See also the [examples](examples).
36+
37+
## Install
38+
39+
The recommended way to install this library is [through composer](https://getcomposer.org).
40+
[New to composer?](https://getcomposer.org/doc/00-intro.md)
41+
42+
```JSON
43+
{
44+
"require": {
45+
"clue/tar-react": "dev-master"
46+
}
47+
}
48+
```
49+
50+
## License
51+
52+
MIT

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "clue/tar-react",
3+
"description": "Async, streaming parser for the TAR file format (Tape ARchive), built on top of React PHP",
4+
"keywords": ["tar", "archive", "parser", "decoder", "extractor", "unpacker", "ReactPHP", "async"],
5+
"homepage": "https://github.com/clue/php-tar-react",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Christian Lück",
10+
"email": "christian@lueck.tv"
11+
}
12+
],
13+
"require": {
14+
"php": ">=5.3",
15+
"react/stream": "~0.4.0|~0.3.0"
16+
},
17+
"require-dev": {
18+
"react/event-loop": "~0.4.0|~0.3.0",
19+
"react/promise": "~2.0|~1.0",
20+
"clue/hexdump": "~0.2.0"
21+
},
22+
"autoload": {
23+
"psr-4": { "Clue\\React\\Tar\\": "src/" }
24+
}
25+
}

examples/dump.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use React\Stream\Stream;
4+
use React\EventLoop\Factory;
5+
use Clue\React\Tar\Decoder;
6+
use React\Stream\BufferedSink;
7+
use Clue\Hexdump\Hexdump;
8+
use React\EventLoop\StreamSelectLoop;
9+
10+
require __DIR__ . '/../vendor/autoload.php';
11+
12+
$in = isset($argv[1]) ? $argv[1] : (__DIR__ . '/../tests/fixtures/alice-bob.tar');
13+
echo 'Reading file "' . $in . '" (pass as argument to example)' . PHP_EOL;
14+
15+
// using the default loop does *not* work for file I/O
16+
//$loop = Factory::create();
17+
$loop = new StreamSelectLoop();
18+
19+
$stream = new Stream(fopen($in, 'r'), $loop);
20+
21+
$decoder = new Decoder();
22+
$decoder->on('entry', function ($header, $file) {
23+
static $i = 0;
24+
echo 'FILE #' . ++$i . PHP_EOL;
25+
26+
27+
echo 'Received entry headers:' . PHP_EOL;
28+
var_dump($header);
29+
30+
BufferedSink::createPromise($file)->then(function ($contents) {
31+
echo 'Received entry contents (' . strlen($contents) . ' bytes)' . PHP_EOL;
32+
33+
$d = new Hexdump();
34+
echo $d->dump($contents) . PHP_EOL . PHP_EOL;
35+
});
36+
});
37+
$decoder->on('error', function ($error) {
38+
echo 'ERROR: ' . $error . PHP_EOL;
39+
});
40+
$decoder->on('close', function() {
41+
echo 'CLOSED' . PHP_EOL;
42+
});
43+
44+
$stream->pipe($decoder);
45+
46+
$loop->run();

phpunit.xml.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap="tests/bootstrap.php"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
>
9+
<testsuites>
10+
<testsuite name="Tar React Test Suite">
11+
<directory>./tests/</directory>
12+
</testsuite>
13+
</testsuites>
14+
<filter>
15+
<whitelist>
16+
<directory>./src/</directory>
17+
</whitelist>
18+
</filter>
19+
</phpunit>

0 commit comments

Comments
 (0)