mirror of
https://github.com/OPSnet/bencode-torrent.git
synced 2026-11-07 18:34:54 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42f5170482 | ||
|
|
917cf865a9 | ||
|
|
ca9617422a |
No files matched your search
@@ -12,7 +12,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['7.2', '7.3', '7.4']
|
||||
php-version: ['7.2', '7.3', '7.4', '8.0']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2"
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8",
|
||||
|
||||
+14
-8
@@ -105,8 +105,8 @@ class BencodeTorrent extends Bencode
|
||||
return strlen($element) === 0;
|
||||
}
|
||||
);
|
||||
if (count($filter) > 0) {
|
||||
throw new \RuntimeException('Cannot have empty path for a file');
|
||||
if (count($filter) === count($file[$path_key]) && $file['length'] !== 0) {
|
||||
throw new \RuntimeException('Cannot have a file with no path');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,10 +209,6 @@ class BencodeTorrent extends Bencode
|
||||
* 'official' flag (no accepted BEP on it), but it has become the defacto standard with more
|
||||
* clients supporting it natively. Returns a boolean on whether or not the source was changed
|
||||
* so that an appropriate screen can be shown to the user.
|
||||
*
|
||||
* @param string $source
|
||||
*
|
||||
* @return bool true if the source was set/changed, false if no change
|
||||
*/
|
||||
public function setSource(string $source): bool
|
||||
{
|
||||
@@ -228,19 +224,29 @@ class BencodeTorrent extends Bencode
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source flag if one has been set
|
||||
*/
|
||||
public function getSource(): ?string
|
||||
{
|
||||
$this->hasData();
|
||||
return $this->data['info']['source'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the creation date for torrent if one has been set
|
||||
*/
|
||||
public function getCreationDate(): ?int
|
||||
{
|
||||
$this->hasData();
|
||||
return $this->data['creation date'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to allow you set any number of keys and values in the data dictionary. You can
|
||||
* set the value in a dictionary by concatenating the keys into a string with a period
|
||||
* separator (ex: info.name will set name field in the info dictionary) so that the rest
|
||||
* of the dictionary is unaffected.
|
||||
*
|
||||
* @param array $array
|
||||
*/
|
||||
public function setValue(array $array): void
|
||||
{
|
||||
|
||||
@@ -144,6 +144,7 @@ class BencodeTorrentTest extends \PHPUnit\Framework\TestCase
|
||||
]
|
||||
];
|
||||
$this->assertEquals($file_list, $bencode->getFileList());
|
||||
$this->assertSame(1425699508, $bencode->getCreationDate());
|
||||
}
|
||||
|
||||
public function testSetData(): void
|
||||
@@ -464,7 +465,7 @@ class BencodeTorrentTest extends \PHPUnit\Framework\TestCase
|
||||
$bencode->getEncode();
|
||||
}
|
||||
|
||||
public function testInvalidPath(): void
|
||||
public function testEmptyPathPart(): void
|
||||
{
|
||||
$data = [
|
||||
'encoding' => 'UTF8',
|
||||
@@ -472,7 +473,44 @@ class BencodeTorrentTest extends \PHPUnit\Framework\TestCase
|
||||
'files' => [
|
||||
0 => [
|
||||
'length' => 1234,
|
||||
'path' => ['']
|
||||
'path' => [
|
||||
'',
|
||||
'01 - test test',
|
||||
]
|
||||
]
|
||||
],
|
||||
'name' => 'test',
|
||||
'length' => 1213134,
|
||||
'pieces' => 'fake pieces string'
|
||||
]
|
||||
];
|
||||
$bencode = new BencodeTorrent();
|
||||
$bencode->setData($data);
|
||||
$this->assertSame(
|
||||
[
|
||||
'total_size' => 1234,
|
||||
'files' => [
|
||||
0 => [
|
||||
'path' => '/01 - test test',
|
||||
'size' => 1234,
|
||||
],
|
||||
],
|
||||
],
|
||||
$bencode->getFileList()
|
||||
);
|
||||
}
|
||||
|
||||
public function testEmptyPath(): void
|
||||
{
|
||||
$data = [
|
||||
'encoding' => 'UTF8',
|
||||
'info' => [
|
||||
'files' => [
|
||||
0 => [
|
||||
'length' => 1234,
|
||||
'path' => [
|
||||
'',
|
||||
]
|
||||
]
|
||||
],
|
||||
'name' => 'test',
|
||||
|
||||
Reference in new issue
Block a user