From 79ef4ac5a4f6fb5f20f0cc260447002e2d140ebd Mon Sep 17 00:00:00 2001 From: Yada Clintjens Date: Wed, 17 Jan 2024 09:52:41 +0100 Subject: [PATCH] Improve documentation and fix typos --- README.md | 20 ++++++++++---------- examples/dump.php | 13 ++++--------- src/Decoder.php | 4 ++-- tests/FunctionalDecoderTest.php | 2 +- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 8540419..a8365a8 100644 --- a/README.md +++ b/README.md @@ -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/). @@ -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']; @@ -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 diff --git a/examples/dump.php b/examples/dump.php index eea3e60..ec992a3 100644 --- a/examples/dump.php +++ b/examples/dump.php @@ -1,19 +1,14 @@ 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; @@ -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; }); }); diff --git a/src/Decoder.php b/src/Decoder.php index d26ad43..2ad8c7d 100644 --- a/src/Decoder.php +++ b/src/Decoder.php @@ -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; diff --git a/tests/FunctionalDecoderTest.php b/tests/FunctionalDecoderTest.php index 8034e75..11c6e06 100644 --- a/tests/FunctionalDecoderTest.php +++ b/tests/FunctionalDecoderTest.php @@ -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());