Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation and examples #20

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clue/reactphp-tar

[![CI status](https://github.com/clue/reactphp-tar/workflows/CI/badge.svg)](https://github.com/clue/reactphp-tar/actions)
[![CI status](https://github.com/clue/reactphp-tar/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-tar/actions)
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/tar-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/tar-react)

Streaming parser to extract tarballs with [ReactPHP](https://reactphp.org/).
Expand Down Expand Up @@ -31,9 +31,9 @@ tar stream into the `Decoder` which emits "entry" events for each individual fil

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

$stream = new ReadableResourceStream(fopen('archive.tar', 'r'));
$stream = new React\Stream\ReadableResourceStream(fopen('archive.tar', 'r'));

$decoder = new Decoder();
$decoder = new Clue\React\Tar\Decoder();

$decoder->on('entry', function (array $header, React\Stream\ReadableStreamInterface $file) {
echo 'File ' . $header['filename'];
Expand All @@ -47,39 +47,39 @@ $decoder->on('entry', function (array $header, React\Stream\ReadableStreamInterf
$stream->pipe($decoder);
```

See also the [examples](examples).
See also the [examples](examples/).

## Install

The recommended way to install this library is [through Composer](https://getcomposer.org).
The recommended way to install this library is [through Composer](https://getcomposer.org/).
[New to Composer?](https://getcomposer.org/doc/00-intro.md)

While in beta, this project does not currently follow [SemVer](https://semver.org/).
This will install the latest supported version:

```bash
$ composer require clue/tar-react:^0.2
composer require clue/tar-react:^0.2
```

See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 8+.
It's *highly recommended to use PHP 7+* for this project.
It's *highly recommended to use the latest supported PHP version* for this project.

## Tests

To run the test suite, you first need to clone this repo and then install all
dependencies [through Composer](https://getcomposer.org):
dependencies [through Composer](https://getcomposer.org/):

```bash
$ composer install
composer install
```

To run the test suite, go to the project root and run:

```bash
$ vendor/bin/phpunit
vendor/bin/phpunit
```

## License
Expand Down
13 changes: 4 additions & 9 deletions examples/dump.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<?php

use Clue\Hexdump\Hexdump;
use Clue\React\Tar\Decoder;
use React\Stream\ReadableResourceStream;
use React\Stream\ReadableStreamInterface;

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

$in = isset($argv[1]) ? $argv[1] : (__DIR__ . '/../tests/fixtures/alice-bob.tar');
echo 'Reading file "' . $in . '" (pass as argument to example)' . PHP_EOL;

$stream = new ReadableResourceStream(fopen($in, 'r'));
$stream = new React\Stream\ReadableResourceStream(fopen($in, 'r'));

$decoder = new Decoder();
$decoder->on('entry', function (array $header, ReadableStreamInterface $file) {
$decoder = new Clue\React\Tar\Decoder();
$decoder->on('entry', function (array $header, React\Stream\ReadableStreamInterface $file) {
static $i = 0;
echo 'FILE #' . ++$i . PHP_EOL;

Expand All @@ -27,7 +22,7 @@
$file->on('close', function () use (&$contents) {
echo 'Received entry contents (' . strlen($contents) . ' bytes)' . PHP_EOL;

$d = new Hexdump();
$d = new Clue\Hexdump\Hexdump();
echo $d->dump($contents) . PHP_EOL . PHP_EOL;
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ private function readHeader($header)
throw new RuntimeException('Invalid header checksum, expected "' . $record['checksum'] . '", but calculated "' . $checksum . '" (looks like the archive is corrupted)');
}

// padding consits of X NULL bytes after record entry until next BLOCK_SIZE boundary
// padding consists of X NULL bytes after record entry until next BLOCK_SIZE boundary
$record['padding'] = (self::BLOCK_SIZE - ($record['size'] % self::BLOCK_SIZE)) % self::BLOCK_SIZE;

// filename consits of prefix and name
// filename consists of prefix and name
$record['filename'] = $record['prefix'] . $record['name'];

return $record;
Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionalDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testStreamingSingleEmptyEmitsSingleEntryWithEmptyStream()
Loop::run();
}

public function testCompleteEndSingleEmtpyBehavesSameAsStreaming()
public function testCompleteEndSingleEmptyBehavesSameAsStreaming()
{
$this->decoder->on('entry', $this->expectCallableOnce());
$this->decoder->on('close', $this->expectCallableOnce());
Expand Down
Loading