-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jakubboucek/v2
Project design update & refctoring
- Loading branch information
Showing
58 changed files
with
12,061 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.gitignore export-ignore | ||
.github export-ignore | ||
example.php export-ignore | ||
tests export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/vendor | ||
composer.lock | ||
/.phpunit.result.cache | ||
/composer.lock | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,15 @@ Reader for TAR and TAR+GZip Archives, optimized for read huge size archives, eff | |
## Features | ||
|
||
- Read **TAR archives** from disk | ||
- Support **GZipped archives** | ||
- Support **GZipped** and **BZipped** archives | ||
- Iterate over Archive content | ||
- Get **name**, **size** and **type** of each file | ||
- Recognize Directory files type | ||
- Recognize Regular files type | ||
- Get **content** of files | ||
- Scan file list only mode (doesn't read file's content from disk) | ||
- Allows to export content to files | ||
- Optimized for performance and low-memory | ||
- Use stream-first access - file content not stored to memory | ||
|
||
## Install | ||
|
||
|
@@ -23,40 +25,40 @@ composer require jakubboucek/tar-stream-reader | |
|
||
Read files from an archive: | ||
```php | ||
foreach (ArchiveReader::read('example.tar') as $filename => $fileInfo) { | ||
echo "File {$filename} is {$fileInfo->getSize()} bytes size, content of file:\n"; | ||
echo $fileInfo->getContent() . "\n\n"; | ||
} | ||
``` | ||
use JakubBoucek\Tar; | ||
|
||
Only scan files from an archive: | ||
```php | ||
foreach (ArchiveReader::scan('example.tar') as $filename => $fileInfo) { | ||
echo "File {$filename} is {$fileInfo->getSize()} bytes size.\n"; | ||
foreach (new Tar\FileReader('example.tar') as $file) { | ||
echo "File {$file->getName()} is {$file->getSize()} bytes size, content of file:\n"; | ||
echo $fileInfo->getContent() . "\n"; | ||
} | ||
``` | ||
Scan mode is skipping contents od files in Archive. It's faster and less memory consume than read mode. | ||
|
||
Define type of archive: | ||
Package recognizes few types of Archive when using classic filename extension (e.g.: `.tar`, `.tgz`, `.tar.bz2`), but | ||
You can explicitly define archive type thought second parameter: | ||
```php | ||
foreach (ArchiveReader::scan('example.tgz') as $filename => $fileInfo) { | ||
echo "File {$filename} is {$fileInfo->getSize()} bytes size.\n"; | ||
use JakubBoucek\Tar; | ||
|
||
foreach (new Tar\FileReader('example.tar+gzip', new Tar\Filehandler\Gzip()) as $file) { | ||
echo "File {$file->getName()} is {$file->getSize()} bytes size.\n"; | ||
} | ||
``` | ||
Package recognize right type of Archive when using classic filename extension (`.tar`, `.tgz`, `.tar.gz`), but you can | ||
set archive type manually by second parameter `ArchiveReader::TYPE_GZ`: | ||
|
||
Package allows to process any type of stream, use `StreamReader` instead of `FileReader`: | ||
```php | ||
foreach (ArchiveReader::scan('example.tar+gzip', ArchiveReader::TYPE_GZ) as $filename => $fileInfo) { | ||
echo "File {$filename} is {$fileInfo->getSize()} bytes size.\n"; | ||
use JakubBoucek\Tar; | ||
|
||
$stream = someBeatifulFuntionToGetStream(); | ||
|
||
foreach (new Tar\StreamReader($stream) as $file) { | ||
echo "File {$file->getName()} is {$file->getSize()} bytes size.\n"; | ||
} | ||
``` | ||
|
||
|
||
## FAQ | ||
|
||
### Can I use Package for ZIP, RAR, BZ, … archives? | ||
### Can I use Package for ZIP, RAR, … archives? | ||
|
||
No, Package recognize only TAR Archive format, additionaly recognize GZipped Archive. | ||
No, Package recognize only TAR Archive format, additionaly recognize GZipped or BZipped Archive. | ||
|
||
### Can I use Package to create/modify Archive? | ||
|
||
|
@@ -71,8 +73,8 @@ No, TAR Archive is stream-based format, it does not support search, you must alw | |
Here are two scopes of this question: **Archive size** or **Size of files in Archive** | ||
|
||
- **Archive size** is teoretically unlimited, beacuse package is using stream very effective. | ||
- **Size of files in Archive** is in read mode limited to available RAM because Content of each file is directly | ||
loaded to variable. For each file content is not available another read method. | ||
- **Size of files in Archive** is teoretically unlimited when use steam-based method to extraxt content | ||
(`toFile()` or `toStream()`), otherwise is size limited with available memory, because is content filled into variable. | ||
|
||
## Contributing | ||
Please don't hesitate send Issue or Pull Request. | ||
|
@@ -81,4 +83,4 @@ Please don't hesitate send Issue or Pull Request. | |
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## License | ||
The MIT License (MIT). Please see [License File](LICENSE) for more information. | ||
The MIT License (MIT). Please see [License File](LICENSE) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
{ | ||
"name": "jakubboucek/tar-stream-reader", | ||
"description": "Reader for TAR and TAR+GZip Archives, optimized for read huge size archives, effective memory usage.", | ||
"type": "library", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Jakub Bouček", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.3", | ||
"ext-zlib": "*" | ||
"php": "~8.0.0 || ~8.1.0 || ~8.2.0", | ||
"psr/http-message": "~1.0 || ~2.0" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^0.12.83", | ||
"symplify/easy-coding-standard": "^9.2" | ||
"phpstan/phpstan": "1.10.18", | ||
"phpunit/phpunit": "^9.0 || ^10.0" | ||
}, | ||
"suggest": { | ||
"ext-bz2": "Needed to support BZ2 compressed archive format", | ||
"ext-zlib": "Needed to support GZipped archive format" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"JakubBoucek\\Tar\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"JakubBoucek\\Tar\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"phpstan": "phpstan analyse src --level 7", | ||
"ecs": "ecs check src", | ||
"ecs-fix": "ecs check src --fix" | ||
"test": "phpunit tests" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheResultFile=".phpunit.result.cache" | ||
failOnWarning="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit tests"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true"> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JakubBoucek\Tar\Exception; | ||
|
||
class EofException extends \RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JakubBoucek\Tar\Exception; | ||
|
||
class FileContentClosedException extends \LogicException | ||
{ | ||
} |
Oops, something went wrong.