Skip to content
Open
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ if ($sevenZip->checkSupport(['zip', 'tar', '7z'])) {
- [x] Auto untar on extraction
- [x] Filter files by patterns
- [x] Encrypt and decrypt
- [ ] Test files using 7z test command
- [x] Test files using 7z test command
- [x] Detect supported formats by the OS
- [x] Add built-in binaries for mac and linux
- [x] ~~Use docker for PHPUnit tests~~ not needed with built-in binaries
Expand Down Expand Up @@ -883,6 +883,22 @@ Configures maximum compression settings based on the specified format.

**Returns**: The current instance for method chaining.

### `verify(): string`

Tests the integrity of an archive.

**Returns**: The output of the 7-Zip command.

**Throws**

- `InvalidArgumentException`: If the archive path (source) is not set.

**Example**

```php
$sevenZip->source('/path/to/archive.7z')->verify();
```

## License

This package is open-sourced software licensed under the [MIT license](./LICENSE.md).
Expand Down
30 changes: 1 addition & 29 deletions src/SevenZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -1157,41 +1157,13 @@ public function rename(array $renames): string
public function test(): bool
{
try {
$this->testWithDetails();
$this->verify();
return true;
} catch (\RuntimeException $e) {
return false;
}
}

/**
* Test the integrity of an archive with detailed output.
*
* @return string The output of the test command.
* @throws \InvalidArgumentException If the source path is not set.
* @throws \RuntimeException If the archive is corrupted or invalid.
*/
public function testWithDetails(): string
{
if (!$this->getSourcePath()) {
throw new \InvalidArgumentException('Archive path (source) must be set');
}

if ($this->getPassword()) {
$this->addFlag('p', $this->getPassword(), glued: true);
}

$command = [
$this->getSevenZipPath(),
't',
...$this->flagrize($this->getAlwaysFlags()),
...$this->flagrize($this->getCustomFlags()),
$this->getSourcePath(),
];

return $this->runCommand($command);
}

/**
* Format flags and values into an array of strings suitable for passing to 7-Zip commands.
*
Expand Down
Loading