Skip to content

Commit

Permalink
Improve documentation and fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
yadaiio committed Jan 26, 2024
1 parent 4faf1c4 commit 79ef4ac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
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

0 comments on commit 79ef4ac

Please sign in to comment.