diff --git a/src/Assembler.php b/src/Assembler.php index beedb81..d737951 100644 --- a/src/Assembler.php +++ b/src/Assembler.php @@ -36,6 +36,7 @@ public function assemble(array $fragments): ResilientData } } } + $resilientData = ResilientData::fromBinaryData($data); if (!$resilientData->getHash()->equals($manifest->resilientDataHash)) { diff --git a/src/ResilientData.php b/src/ResilientData.php index 81eaa5f..fe9affb 100644 --- a/src/ResilientData.php +++ b/src/ResilientData.php @@ -6,9 +6,25 @@ class ResilientData { - public function __construct(private readonly mixed $data) {} + private function __construct(private readonly string $data) {} - public function getData(): mixed + public static function fromFile(string $filename): self + { + $data = file_get_contents($filename); + + if (false === $data) { + throw new \RuntimeException('Could not read the file'); + } + + return new self($data); + } + + public static function fromString(string $data): self + { + return new self($data); + } + + public function getData(): string { return $this->data; } @@ -20,17 +36,11 @@ public function getHash(): Hash public function getBinaryData(): string { - $stringData = json_encode($this->data); - - if (false === $stringData) { - throw new \RuntimeException('Failed to encode data to JSON: '.json_last_error_msg()); - } - - return base64_encode($stringData); + return base64_encode($this->data); } - public static function fromBinaryData(string $data): self + public static function fromBinaryData(string $binaryData): self { - return new self(json_decode(base64_decode($data))); + return new self(base64_decode($binaryData)); } } diff --git a/tests/fixtures/fragments/fragment_0.txt b/tests/fixtures/fragments/fragment_0.txt index 535753c..44212eb 100644 --- a/tests/fixtures/fragments/fragment_0.txt +++ b/tests/fixtures/fragments/fragment_0.txt @@ -1 +1 @@ -O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:7;}s:4:"data";s:274:"IkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0LCBjb25zZWN0ZXR1ciBhZGlwaXNjaW5nIGVsaXQuIFNlZCBub24gcmlzdXMuIFN1c3BlbmRpc3NlIGxlY3R1cyB0b3J0b3IsIGRpZ25pc3NpbSBzaXQgYW1ldCwgYWRpcGlzY2luZyBuZWMsIHVsdHJpY2llcyBzZWQsIGRvbG9yLiBDcmFzIGVsZW1lbnR1bSB1bHRyaWNlcyBkaWFtLiBNYWVjZW5hcyBsaWd1bGEgbW";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:11;}s:4:"data";s:274:"Fzc2EsIHZhcml1cyBhLCBzZW1wZXIgY29uZ3VlLCBldWlzbW9kIG5vbiwgbWkuIFByb2luIHBvcnR0aXRvciwgb3JjaSBuZWMgbm9udW1teSBtb2xlc3RpZSwgZW5pbSBlc3QgZWxlaWZlbmQgbWksIG5vbiBmZXJtZW50dW0gZGlhbSBuaXNsIHNpdCBhbWV0IGVyYXQuIER1aXMgc2VtcGVyLiBEdWlzIGFyY3UgbWFzc2EsIHNjZWxlcmlzcXVlIHZpdGFlLCBjb25z";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:13;}s:4:"data";s:274:"ZXF1YXQgaW4sIHByZXRpdW0gYSwgZW5pbS4gUGVsbGVudGVzcXVlIGNvbmd1ZS4gVXQgaW4gcmlzdXMgdm9sdXRwYXQgbGliZXJvIHBoYXJldHJhIHRlbXBvci4gQ3JhcyB2ZXN0aWJ1bHVtIGJpYmVuZHVtIGF1Z3VlLiBQcmFlc2VudCBlZ2VzdGFzIGxlbyBpbiBwZWRlLiBQcmFlc2VudCBibGFuZGl0IG9kaW8gZXUgZW5pbS4gUGVsbGVudGVzcXVlIHNlZCBkdW";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:19;}s:4:"data";s:274:"b24gZGlhbSBzb2RhbGVzIGhlbmRyZXJpdC5cblV0IHZlbGl0IG1hdXJpcywgZWdlc3RhcyBzZWQsIGdyYXZpZGEgbmVjLCBvcm5hcmUgdXQsIG1pLiBBZW5lYW4gdXQgb3JjaSB2ZWwgbWFzc2Egc3VzY2lwaXQgcHVsdmluYXIuIE51bGxhIHNvbGxpY2l0dWRpbi4gRnVzY2UgdmFyaXVzLCBsaWd1bGEgbm9uIHRlbXB1cyBhbGlxdWFtLCBudW5jIHR1cnBpcyB1bG";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:21;}s:4:"data";s:274:"xhbWNvcnBlciBuaWJoLCBpbiB0ZW1wdXMgc2FwaWVuIGVyb3Mgdml0YWUgbGlndWxhLiBQZWxsZW50ZXNxdWUgcmhvbmN1cyBudW5jIGV0IGF1Z3VlLiBJbnRlZ2VyIGlkIGZlbGlzLiBDdXJhYml0dXIgYWxpcXVldCBwZWxsZW50ZXNxdWUgZGlhbS4gSW50ZWdlciBxdWlzIG1ldHVzIHZpdGFlIGVsaXQgbG9ib3J0aXMgZWdlc3Rhcy4gTG9yZW0gaXBzdW0gZG9s";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:25;}s:4:"data";s:274:"RhZSBlcmF0LiBQcm9pbiBmZXVnaWF0LCBhdWd1ZSBub24gZWxlbWVudHVtIHBvc3VlcmUsIG1ldHVzIHB1cnVzIGlhY3VsaXMgbGVjdHVzLCBldCB0cmlzdGlxdWUgbGlndWxhIGp1c3RvIHZpdGFlIG1hZ25hLlxuQWxpcXVhbSBjb252YWxsaXMgc29sbGljaXR1ZGluIHB1cnVzLiBQcmFlc2VudCBhbGlxdWFtLCBlbmltIGF0IGZlcm1lbnR1bSBtb2xsaXMsIGxp";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:0;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"e5a00d17fdf9193553d3201f96594ed5ebf28c1932c1a19057863f67a4525972";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file +O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:7;}s:4:"data";s:274:"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gU2VkIG5vbiByaXN1cy4gU3VzcGVuZGlzc2UgbGVjdHVzIHRvcnRvciwgZGlnbmlzc2ltIHNpdCBhbWV0LCBhZGlwaXNjaW5nIG5lYywgdWx0cmljaWVzIHNlZCwgZG9sb3IuIENyYXMgZWxlbWVudHVtIHVsdHJpY2VzIGRpYW0uIE1hZWNlbmFzIGxpZ3VsYSBtYX";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:11;}s:4:"data";s:274:"NzYSwgdmFyaXVzIGEsIHNlbXBlciBjb25ndWUsIGV1aXNtb2Qgbm9uLCBtaS4gUHJvaW4gcG9ydHRpdG9yLCBvcmNpIG5lYyBub251bW15IG1vbGVzdGllLCBlbmltIGVzdCBlbGVpZmVuZCBtaSwgbm9uIGZlcm1lbnR1bSBkaWFtIG5pc2wgc2l0IGFtZXQgZXJhdC4gRHVpcyBzZW1wZXIuIER1aXMgYXJjdSBtYXNzYSwgc2NlbGVyaXNxdWUgdml0YWUsIGNvbnNl";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:13;}s:4:"data";s:274:"cXVhdCBpbiwgcHJldGl1bSBhLCBlbmltLiBQZWxsZW50ZXNxdWUgY29uZ3VlLiBVdCBpbiByaXN1cyB2b2x1dHBhdCBsaWJlcm8gcGhhcmV0cmEgdGVtcG9yLiBDcmFzIHZlc3RpYnVsdW0gYmliZW5kdW0gYXVndWUuIFByYWVzZW50IGVnZXN0YXMgbGVvIGluIHBlZGUuIFByYWVzZW50IGJsYW5kaXQgb2RpbyBldSBlbmltLiBQZWxsZW50ZXNxdWUgc2VkIGR1aS";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:19;}s:4:"data";s:274:"biBkaWFtIHNvZGFsZXMgaGVuZHJlcml0LgpVdCB2ZWxpdCBtYXVyaXMsIGVnZXN0YXMgc2VkLCBncmF2aWRhIG5lYywgb3JuYXJlIHV0LCBtaS4gQWVuZWFuIHV0IG9yY2kgdmVsIG1hc3NhIHN1c2NpcGl0IHB1bHZpbmFyLiBOdWxsYSBzb2xsaWNpdHVkaW4uIEZ1c2NlIHZhcml1cywgbGlndWxhIG5vbiB0ZW1wdXMgYWxpcXVhbSwgbnVuYyB0dXJwaXMgdWxsYW";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:21;}s:4:"data";s:274:"1jb3JwZXIgbmliaCwgaW4gdGVtcHVzIHNhcGllbiBlcm9zIHZpdGFlIGxpZ3VsYS4gUGVsbGVudGVzcXVlIHJob25jdXMgbnVuYyBldCBhdWd1ZS4gSW50ZWdlciBpZCBmZWxpcy4gQ3VyYWJpdHVyIGFsaXF1ZXQgcGVsbGVudGVzcXVlIGRpYW0uIEludGVnZXIgcXVpcyBtZXR1cyB2aXRhZSBlbGl0IGxvYm9ydGlzIGVnZXN0YXMuIExvcmVtIGlwc3VtIGRvbG9y";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:25;}s:4:"data";s:274:"UgZXJhdC4gUHJvaW4gZmV1Z2lhdCwgYXVndWUgbm9uIGVsZW1lbnR1bSBwb3N1ZXJlLCBtZXR1cyBwdXJ1cyBpYWN1bGlzIGxlY3R1cywgZXQgdHJpc3RpcXVlIGxpZ3VsYSBqdXN0byB2aXRhZSBtYWduYS4KQWxpcXVhbSBjb252YWxsaXMgc29sbGljaXR1ZGluIHB1cnVzLiBQcmFlc2VudCBhbGlxdWFtLCBlbmltIGF0IGZlcm1lbnR1bSBtb2xsaXMsIGxpZ3Vs";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:0;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"ccec74f22f298deb6bc62053b4043839561ea1a08650e7d79f798b6e018202a6";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file diff --git a/tests/fixtures/fragments/fragment_1.txt b/tests/fixtures/fragments/fragment_1.txt index f905cd8..35a2fe0 100644 --- a/tests/fixtures/fragments/fragment_1.txt +++ b/tests/fixtures/fragments/fragment_1.txt @@ -1 +1 @@ -O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:7;}s:4:"data";s:274:"IkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0LCBjb25zZWN0ZXR1ciBhZGlwaXNjaW5nIGVsaXQuIFNlZCBub24gcmlzdXMuIFN1c3BlbmRpc3NlIGxlY3R1cyB0b3J0b3IsIGRpZ25pc3NpbSBzaXQgYW1ldCwgYWRpcGlzY2luZyBuZWMsIHVsdHJpY2llcyBzZWQsIGRvbG9yLiBDcmFzIGVsZW1lbnR1bSB1bHRyaWNlcyBkaWFtLiBNYWVjZW5hcyBsaWd1bGEgbW";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:11;}s:4:"data";s:274:"Fzc2EsIHZhcml1cyBhLCBzZW1wZXIgY29uZ3VlLCBldWlzbW9kIG5vbiwgbWkuIFByb2luIHBvcnR0aXRvciwgb3JjaSBuZWMgbm9udW1teSBtb2xlc3RpZSwgZW5pbSBlc3QgZWxlaWZlbmQgbWksIG5vbiBmZXJtZW50dW0gZGlhbSBuaXNsIHNpdCBhbWV0IGVyYXQuIER1aXMgc2VtcGVyLiBEdWlzIGFyY3UgbWFzc2EsIHNjZWxlcmlzcXVlIHZpdGFlLCBjb25z";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:14;}s:4:"data";s:274:"kgdXQgYXVndWUgYmxhbmRpdCBzb2RhbGVzLiBWZXN0aWJ1bHVtIGFudGUgaXBzdW0gcHJpbWlzIGluIGZhdWNpYnVzIG9yY2kgbHVjdHVzIGV0IHVsdHJpY2VzIHBvc3VlcmUgY3ViaWxpYSBDdXJhZTsgQWxpcXVhbSBuaWJoLiBNYXVyaXMgYWMgbWF1cmlzIHNlZCBwZWRlIHBlbGxlbnRlc3F1ZSBmZXJtZW50dW0uIE1hZWNlbmFzIGFkaXBpc2NpbmcgYW50ZSBu";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:19;}s:4:"data";s:274:"b24gZGlhbSBzb2RhbGVzIGhlbmRyZXJpdC5cblV0IHZlbGl0IG1hdXJpcywgZWdlc3RhcyBzZWQsIGdyYXZpZGEgbmVjLCBvcm5hcmUgdXQsIG1pLiBBZW5lYW4gdXQgb3JjaSB2ZWwgbWFzc2Egc3VzY2lwaXQgcHVsdmluYXIuIE51bGxhIHNvbGxpY2l0dWRpbi4gRnVzY2UgdmFyaXVzLCBsaWd1bGEgbm9uIHRlbXB1cyBhbGlxdWFtLCBudW5jIHR1cnBpcyB1bG";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:22;}s:4:"data";s:274:"b3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIE1vcmJpIHZlbCBlcmF0IG5vbiBtYXVyaXMgY29udmFsbGlzIHZlaGljdWxhLiBOdWxsYSBldCBzYXBpZW4uIEludGVnZXIgdG9ydG9yIHRlbGx1cywgYWxpcXVhbSBmYXVjaWJ1cywgY29udmFsbGlzIGlkLCBjb25ndWUgZXUsIHF1YW0uIE1hdXJpcyB1bGxhbWNvcnBlciBmZWxpcyB2aX";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:26;}s:4:"data";s:274:"Z3VsYSBtYXNzYSBhZGlwaXNjaW5nIG5pc2wsIGFjIGV1aXNtb2QgbmliaCBuaXNsIGV1IGxlY3R1cy4gRnVzY2UgdnVscHV0YXRlIHNlbSBhdCBzYXBpZW4uIFZpdmFtdXMgbGVvLiBBbGlxdWFtIGV1aXNtb2QgbGliZXJvIGV1IGVuaW0uIE51bGxhIG5lYyBmZWxpcyBzZWQgbGVvIHBsYWNlcmF0IGltcGVyZGlldC4gQWVuZWFuIHN1c2NpcGl0IG51bGxhIGluIG";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:1;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"e5a00d17fdf9193553d3201f96594ed5ebf28c1932c1a19057863f67a4525972";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file +O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:7;}s:4:"data";s:274:"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gU2VkIG5vbiByaXN1cy4gU3VzcGVuZGlzc2UgbGVjdHVzIHRvcnRvciwgZGlnbmlzc2ltIHNpdCBhbWV0LCBhZGlwaXNjaW5nIG5lYywgdWx0cmljaWVzIHNlZCwgZG9sb3IuIENyYXMgZWxlbWVudHVtIHVsdHJpY2VzIGRpYW0uIE1hZWNlbmFzIGxpZ3VsYSBtYX";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:11;}s:4:"data";s:274:"NzYSwgdmFyaXVzIGEsIHNlbXBlciBjb25ndWUsIGV1aXNtb2Qgbm9uLCBtaS4gUHJvaW4gcG9ydHRpdG9yLCBvcmNpIG5lYyBub251bW15IG1vbGVzdGllLCBlbmltIGVzdCBlbGVpZmVuZCBtaSwgbm9uIGZlcm1lbnR1bSBkaWFtIG5pc2wgc2l0IGFtZXQgZXJhdC4gRHVpcyBzZW1wZXIuIER1aXMgYXJjdSBtYXNzYSwgc2NlbGVyaXNxdWUgdml0YWUsIGNvbnNl";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:14;}s:4:"data";s:274:"B1dCBhdWd1ZSBibGFuZGl0IHNvZGFsZXMuIFZlc3RpYnVsdW0gYW50ZSBpcHN1bSBwcmltaXMgaW4gZmF1Y2lidXMgb3JjaSBsdWN0dXMgZXQgdWx0cmljZXMgcG9zdWVyZSBjdWJpbGlhIEN1cmFlOyBBbGlxdWFtIG5pYmguIE1hdXJpcyBhYyBtYXVyaXMgc2VkIHBlZGUgcGVsbGVudGVzcXVlIGZlcm1lbnR1bS4gTWFlY2VuYXMgYWRpcGlzY2luZyBhbnRlIG5v";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:19;}s:4:"data";s:274:"biBkaWFtIHNvZGFsZXMgaGVuZHJlcml0LgpVdCB2ZWxpdCBtYXVyaXMsIGVnZXN0YXMgc2VkLCBncmF2aWRhIG5lYywgb3JuYXJlIHV0LCBtaS4gQWVuZWFuIHV0IG9yY2kgdmVsIG1hc3NhIHN1c2NpcGl0IHB1bHZpbmFyLiBOdWxsYSBzb2xsaWNpdHVkaW4uIEZ1c2NlIHZhcml1cywgbGlndWxhIG5vbiB0ZW1wdXMgYWxpcXVhbSwgbnVuYyB0dXJwaXMgdWxsYW";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:22;}s:4:"data";s:274:"IHNpdCBhbWV0LCBjb25zZWN0ZXR1ZXIgYWRpcGlzY2luZyBlbGl0LiBNb3JiaSB2ZWwgZXJhdCBub24gbWF1cmlzIGNvbnZhbGxpcyB2ZWhpY3VsYS4gTnVsbGEgZXQgc2FwaWVuLiBJbnRlZ2VyIHRvcnRvciB0ZWxsdXMsIGFsaXF1YW0gZmF1Y2lidXMsIGNvbnZhbGxpcyBpZCwgY29uZ3VlIGV1LCBxdWFtLiBNYXVyaXMgdWxsYW1jb3JwZXIgZmVsaXMgdml0YW";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:26;}s:4:"data";s:274:"YSBtYXNzYSBhZGlwaXNjaW5nIG5pc2wsIGFjIGV1aXNtb2QgbmliaCBuaXNsIGV1IGxlY3R1cy4gRnVzY2UgdnVscHV0YXRlIHNlbSBhdCBzYXBpZW4uIFZpdmFtdXMgbGVvLiBBbGlxdWFtIGV1aXNtb2QgbGliZXJvIGV1IGVuaW0uIE51bGxhIG5lYyBmZWxpcyBzZWQgbGVvIHBsYWNlcmF0IGltcGVyZGlldC4gQWVuZWFuIHN1c2NpcGl0IG51bGxhIGluIGp1c3";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:1;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"ccec74f22f298deb6bc62053b4043839561ea1a08650e7d79f798b6e018202a6";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file diff --git a/tests/fixtures/fragments/fragment_2.txt b/tests/fixtures/fragments/fragment_2.txt index 99a9dbc..383053f 100644 --- a/tests/fixtures/fragments/fragment_2.txt +++ b/tests/fixtures/fragments/fragment_2.txt @@ -1 +1 @@ -O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:7;}s:4:"data";s:274:"IkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0LCBjb25zZWN0ZXR1ciBhZGlwaXNjaW5nIGVsaXQuIFNlZCBub24gcmlzdXMuIFN1c3BlbmRpc3NlIGxlY3R1cyB0b3J0b3IsIGRpZ25pc3NpbSBzaXQgYW1ldCwgYWRpcGlzY2luZyBuZWMsIHVsdHJpY2llcyBzZWQsIGRvbG9yLiBDcmFzIGVsZW1lbnR1bSB1bHRyaWNlcyBkaWFtLiBNYWVjZW5hcyBsaWd1bGEgbW";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:13;}s:4:"data";s:274:"ZXF1YXQgaW4sIHByZXRpdW0gYSwgZW5pbS4gUGVsbGVudGVzcXVlIGNvbmd1ZS4gVXQgaW4gcmlzdXMgdm9sdXRwYXQgbGliZXJvIHBoYXJldHJhIHRlbXBvci4gQ3JhcyB2ZXN0aWJ1bHVtIGJpYmVuZHVtIGF1Z3VlLiBQcmFlc2VudCBlZ2VzdGFzIGxlbyBpbiBwZWRlLiBQcmFlc2VudCBibGFuZGl0IG9kaW8gZXUgZW5pbS4gUGVsbGVudGVzcXVlIHNlZCBkdW";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:14;}s:4:"data";s:274:"kgdXQgYXVndWUgYmxhbmRpdCBzb2RhbGVzLiBWZXN0aWJ1bHVtIGFudGUgaXBzdW0gcHJpbWlzIGluIGZhdWNpYnVzIG9yY2kgbHVjdHVzIGV0IHVsdHJpY2VzIHBvc3VlcmUgY3ViaWxpYSBDdXJhZTsgQWxpcXVhbSBuaWJoLiBNYXVyaXMgYWMgbWF1cmlzIHNlZCBwZWRlIHBlbGxlbnRlc3F1ZSBmZXJtZW50dW0uIE1hZWNlbmFzIGFkaXBpc2NpbmcgYW50ZSBu";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:21;}s:4:"data";s:274:"xhbWNvcnBlciBuaWJoLCBpbiB0ZW1wdXMgc2FwaWVuIGVyb3Mgdml0YWUgbGlndWxhLiBQZWxsZW50ZXNxdWUgcmhvbmN1cyBudW5jIGV0IGF1Z3VlLiBJbnRlZ2VyIGlkIGZlbGlzLiBDdXJhYml0dXIgYWxpcXVldCBwZWxsZW50ZXNxdWUgZGlhbS4gSW50ZWdlciBxdWlzIG1ldHVzIHZpdGFlIGVsaXQgbG9ib3J0aXMgZWdlc3Rhcy4gTG9yZW0gaXBzdW0gZG9s";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:22;}s:4:"data";s:274:"b3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIE1vcmJpIHZlbCBlcmF0IG5vbiBtYXVyaXMgY29udmFsbGlzIHZlaGljdWxhLiBOdWxsYSBldCBzYXBpZW4uIEludGVnZXIgdG9ydG9yIHRlbGx1cywgYWxpcXVhbSBmYXVjaWJ1cywgY29udmFsbGlzIGlkLCBjb25ndWUgZXUsIHF1YW0uIE1hdXJpcyB1bGxhbWNvcnBlciBmZWxpcyB2aX";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:28;}s:4:"data";s:274:"p1c3RvLiBTdXNwZW5kaXNzZSBjdXJzdXMgcnV0cnVtIGF1Z3VlLiBOdWxsYSB0aW5jaWR1bnQgdGluY2lkdW50IG1pLiBDdXJhYml0dXIgaWFjdWxpcywgbG9yZW0gdmVsIHJob25jdXMgZmF1Y2lidXMsIGZlbGlzIG1hZ25hIGZlcm1lbnR1bSBhdWd1ZSwgZXQgdWx0cmljaWVzIGxhY3VzIGxvcmVtIHZhcml1cyBwdXJ1cy4gQ3VyYWJpdHVyIGV1IGFtZXRcbiI=";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:2;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"e5a00d17fdf9193553d3201f96594ed5ebf28c1932c1a19057863f67a4525972";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file +O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:7;}s:4:"data";s:274:"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gU2VkIG5vbiByaXN1cy4gU3VzcGVuZGlzc2UgbGVjdHVzIHRvcnRvciwgZGlnbmlzc2ltIHNpdCBhbWV0LCBhZGlwaXNjaW5nIG5lYywgdWx0cmljaWVzIHNlZCwgZG9sb3IuIENyYXMgZWxlbWVudHVtIHVsdHJpY2VzIGRpYW0uIE1hZWNlbmFzIGxpZ3VsYSBtYX";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:13;}s:4:"data";s:274:"cXVhdCBpbiwgcHJldGl1bSBhLCBlbmltLiBQZWxsZW50ZXNxdWUgY29uZ3VlLiBVdCBpbiByaXN1cyB2b2x1dHBhdCBsaWJlcm8gcGhhcmV0cmEgdGVtcG9yLiBDcmFzIHZlc3RpYnVsdW0gYmliZW5kdW0gYXVndWUuIFByYWVzZW50IGVnZXN0YXMgbGVvIGluIHBlZGUuIFByYWVzZW50IGJsYW5kaXQgb2RpbyBldSBlbmltLiBQZWxsZW50ZXNxdWUgc2VkIGR1aS";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:14;}s:4:"data";s:274:"B1dCBhdWd1ZSBibGFuZGl0IHNvZGFsZXMuIFZlc3RpYnVsdW0gYW50ZSBpcHN1bSBwcmltaXMgaW4gZmF1Y2lidXMgb3JjaSBsdWN0dXMgZXQgdWx0cmljZXMgcG9zdWVyZSBjdWJpbGlhIEN1cmFlOyBBbGlxdWFtIG5pYmguIE1hdXJpcyBhYyBtYXVyaXMgc2VkIHBlZGUgcGVsbGVudGVzcXVlIGZlcm1lbnR1bS4gTWFlY2VuYXMgYWRpcGlzY2luZyBhbnRlIG5v";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:21;}s:4:"data";s:274:"1jb3JwZXIgbmliaCwgaW4gdGVtcHVzIHNhcGllbiBlcm9zIHZpdGFlIGxpZ3VsYS4gUGVsbGVudGVzcXVlIHJob25jdXMgbnVuYyBldCBhdWd1ZS4gSW50ZWdlciBpZCBmZWxpcy4gQ3VyYWJpdHVyIGFsaXF1ZXQgcGVsbGVudGVzcXVlIGRpYW0uIEludGVnZXIgcXVpcyBtZXR1cyB2aXRhZSBlbGl0IGxvYm9ydGlzIGVnZXN0YXMuIExvcmVtIGlwc3VtIGRvbG9y";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:22;}s:4:"data";s:274:"IHNpdCBhbWV0LCBjb25zZWN0ZXR1ZXIgYWRpcGlzY2luZyBlbGl0LiBNb3JiaSB2ZWwgZXJhdCBub24gbWF1cmlzIGNvbnZhbGxpcyB2ZWhpY3VsYS4gTnVsbGEgZXQgc2FwaWVuLiBJbnRlZ2VyIHRvcnRvciB0ZWxsdXMsIGFsaXF1YW0gZmF1Y2lidXMsIGNvbnZhbGxpcyBpZCwgY29uZ3VlIGV1LCBxdWFtLiBNYXVyaXMgdWxsYW1jb3JwZXIgZmVsaXMgdml0YW";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:28;}s:4:"data";s:266:"RvLiBTdXNwZW5kaXNzZSBjdXJzdXMgcnV0cnVtIGF1Z3VlLiBOdWxsYSB0aW5jaWR1bnQgdGluY2lkdW50IG1pLiBDdXJhYml0dXIgaWFjdWxpcywgbG9yZW0gdmVsIHJob25jdXMgZmF1Y2lidXMsIGZlbGlzIG1hZ25hIGZlcm1lbnR1bSBhdWd1ZSwgZXQgdWx0cmljaWVzIGxhY3VzIGxvcmVtIHZhcml1cyBwdXJ1cy4gQ3VyYWJpdHVyIGV1IGFtZXQK";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:2;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"ccec74f22f298deb6bc62053b4043839561ea1a08650e7d79f798b6e018202a6";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file diff --git a/tests/fixtures/fragments/fragment_3.txt b/tests/fixtures/fragments/fragment_3.txt index 041ba9d..2a5d8e4 100644 --- a/tests/fixtures/fragments/fragment_3.txt +++ b/tests/fixtures/fragments/fragment_3.txt @@ -1 +1 @@ -O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:11;}s:4:"data";s:274:"Fzc2EsIHZhcml1cyBhLCBzZW1wZXIgY29uZ3VlLCBldWlzbW9kIG5vbiwgbWkuIFByb2luIHBvcnR0aXRvciwgb3JjaSBuZWMgbm9udW1teSBtb2xlc3RpZSwgZW5pbSBlc3QgZWxlaWZlbmQgbWksIG5vbiBmZXJtZW50dW0gZGlhbSBuaXNsIHNpdCBhbWV0IGVyYXQuIER1aXMgc2VtcGVyLiBEdWlzIGFyY3UgbWFzc2EsIHNjZWxlcmlzcXVlIHZpdGFlLCBjb25z";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:13;}s:4:"data";s:274:"ZXF1YXQgaW4sIHByZXRpdW0gYSwgZW5pbS4gUGVsbGVudGVzcXVlIGNvbmd1ZS4gVXQgaW4gcmlzdXMgdm9sdXRwYXQgbGliZXJvIHBoYXJldHJhIHRlbXBvci4gQ3JhcyB2ZXN0aWJ1bHVtIGJpYmVuZHVtIGF1Z3VlLiBQcmFlc2VudCBlZ2VzdGFzIGxlbyBpbiBwZWRlLiBQcmFlc2VudCBibGFuZGl0IG9kaW8gZXUgZW5pbS4gUGVsbGVudGVzcXVlIHNlZCBkdW";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:14;}s:4:"data";s:274:"kgdXQgYXVndWUgYmxhbmRpdCBzb2RhbGVzLiBWZXN0aWJ1bHVtIGFudGUgaXBzdW0gcHJpbWlzIGluIGZhdWNpYnVzIG9yY2kgbHVjdHVzIGV0IHVsdHJpY2VzIHBvc3VlcmUgY3ViaWxpYSBDdXJhZTsgQWxpcXVhbSBuaWJoLiBNYXVyaXMgYWMgbWF1cmlzIHNlZCBwZWRlIHBlbGxlbnRlc3F1ZSBmZXJtZW50dW0uIE1hZWNlbmFzIGFkaXBpc2NpbmcgYW50ZSBu";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:25;}s:4:"data";s:274:"RhZSBlcmF0LiBQcm9pbiBmZXVnaWF0LCBhdWd1ZSBub24gZWxlbWVudHVtIHBvc3VlcmUsIG1ldHVzIHB1cnVzIGlhY3VsaXMgbGVjdHVzLCBldCB0cmlzdGlxdWUgbGlndWxhIGp1c3RvIHZpdGFlIG1hZ25hLlxuQWxpcXVhbSBjb252YWxsaXMgc29sbGljaXR1ZGluIHB1cnVzLiBQcmFlc2VudCBhbGlxdWFtLCBlbmltIGF0IGZlcm1lbnR1bSBtb2xsaXMsIGxp";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:26;}s:4:"data";s:274:"Z3VsYSBtYXNzYSBhZGlwaXNjaW5nIG5pc2wsIGFjIGV1aXNtb2QgbmliaCBuaXNsIGV1IGxlY3R1cy4gRnVzY2UgdnVscHV0YXRlIHNlbSBhdCBzYXBpZW4uIFZpdmFtdXMgbGVvLiBBbGlxdWFtIGV1aXNtb2QgbGliZXJvIGV1IGVuaW0uIE51bGxhIG5lYyBmZWxpcyBzZWQgbGVvIHBsYWNlcmF0IGltcGVyZGlldC4gQWVuZWFuIHN1c2NpcGl0IG51bGxhIGluIG";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:28;}s:4:"data";s:274:"p1c3RvLiBTdXNwZW5kaXNzZSBjdXJzdXMgcnV0cnVtIGF1Z3VlLiBOdWxsYSB0aW5jaWR1bnQgdGluY2lkdW50IG1pLiBDdXJhYml0dXIgaWFjdWxpcywgbG9yZW0gdmVsIHJob25jdXMgZmF1Y2lidXMsIGZlbGlzIG1hZ25hIGZlcm1lbnR1bSBhdWd1ZSwgZXQgdWx0cmljaWVzIGxhY3VzIGxvcmVtIHZhcml1cyBwdXJ1cy4gQ3VyYWJpdHVyIGV1IGFtZXRcbiI=";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:3;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"e5a00d17fdf9193553d3201f96594ed5ebf28c1932c1a19057863f67a4525972";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file +O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:11;}s:4:"data";s:274:"NzYSwgdmFyaXVzIGEsIHNlbXBlciBjb25ndWUsIGV1aXNtb2Qgbm9uLCBtaS4gUHJvaW4gcG9ydHRpdG9yLCBvcmNpIG5lYyBub251bW15IG1vbGVzdGllLCBlbmltIGVzdCBlbGVpZmVuZCBtaSwgbm9uIGZlcm1lbnR1bSBkaWFtIG5pc2wgc2l0IGFtZXQgZXJhdC4gRHVpcyBzZW1wZXIuIER1aXMgYXJjdSBtYXNzYSwgc2NlbGVyaXNxdWUgdml0YWUsIGNvbnNl";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:13;}s:4:"data";s:274:"cXVhdCBpbiwgcHJldGl1bSBhLCBlbmltLiBQZWxsZW50ZXNxdWUgY29uZ3VlLiBVdCBpbiByaXN1cyB2b2x1dHBhdCBsaWJlcm8gcGhhcmV0cmEgdGVtcG9yLiBDcmFzIHZlc3RpYnVsdW0gYmliZW5kdW0gYXVndWUuIFByYWVzZW50IGVnZXN0YXMgbGVvIGluIHBlZGUuIFByYWVzZW50IGJsYW5kaXQgb2RpbyBldSBlbmltLiBQZWxsZW50ZXNxdWUgc2VkIGR1aS";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:14;}s:4:"data";s:274:"B1dCBhdWd1ZSBibGFuZGl0IHNvZGFsZXMuIFZlc3RpYnVsdW0gYW50ZSBpcHN1bSBwcmltaXMgaW4gZmF1Y2lidXMgb3JjaSBsdWN0dXMgZXQgdWx0cmljZXMgcG9zdWVyZSBjdWJpbGlhIEN1cmFlOyBBbGlxdWFtIG5pYmguIE1hdXJpcyBhYyBtYXVyaXMgc2VkIHBlZGUgcGVsbGVudGVzcXVlIGZlcm1lbnR1bS4gTWFlY2VuYXMgYWRpcGlzY2luZyBhbnRlIG5v";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:25;}s:4:"data";s:274:"UgZXJhdC4gUHJvaW4gZmV1Z2lhdCwgYXVndWUgbm9uIGVsZW1lbnR1bSBwb3N1ZXJlLCBtZXR1cyBwdXJ1cyBpYWN1bGlzIGxlY3R1cywgZXQgdHJpc3RpcXVlIGxpZ3VsYSBqdXN0byB2aXRhZSBtYWduYS4KQWxpcXVhbSBjb252YWxsaXMgc29sbGljaXR1ZGluIHB1cnVzLiBQcmFlc2VudCBhbGlxdWFtLCBlbmltIGF0IGZlcm1lbnR1bSBtb2xsaXMsIGxpZ3Vs";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:26;}s:4:"data";s:274:"YSBtYXNzYSBhZGlwaXNjaW5nIG5pc2wsIGFjIGV1aXNtb2QgbmliaCBuaXNsIGV1IGxlY3R1cy4gRnVzY2UgdnVscHV0YXRlIHNlbSBhdCBzYXBpZW4uIFZpdmFtdXMgbGVvLiBBbGlxdWFtIGV1aXNtb2QgbGliZXJvIGV1IGVuaW0uIE51bGxhIG5lYyBmZWxpcyBzZWQgbGVvIHBsYWNlcmF0IGltcGVyZGlldC4gQWVuZWFuIHN1c2NpcGl0IG51bGxhIGluIGp1c3";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:28;}s:4:"data";s:266:"RvLiBTdXNwZW5kaXNzZSBjdXJzdXMgcnV0cnVtIGF1Z3VlLiBOdWxsYSB0aW5jaWR1bnQgdGluY2lkdW50IG1pLiBDdXJhYml0dXIgaWFjdWxpcywgbG9yZW0gdmVsIHJob25jdXMgZmF1Y2lidXMsIGZlbGlzIG1hZ25hIGZlcm1lbnR1bSBhdWd1ZSwgZXQgdWx0cmljaWVzIGxhY3VzIGxvcmVtIHZhcml1cyBwdXJ1cy4gQ3VyYWJpdHVyIGV1IGFtZXQK";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:3;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"ccec74f22f298deb6bc62053b4043839561ea1a08650e7d79f798b6e018202a6";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file diff --git a/tests/fixtures/fragments/fragment_4.txt b/tests/fixtures/fragments/fragment_4.txt index b1a270f..b1f09d7 100644 --- a/tests/fixtures/fragments/fragment_4.txt +++ b/tests/fixtures/fragments/fragment_4.txt @@ -1 +1 @@ -O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:19;}s:4:"data";s:274:"b24gZGlhbSBzb2RhbGVzIGhlbmRyZXJpdC5cblV0IHZlbGl0IG1hdXJpcywgZWdlc3RhcyBzZWQsIGdyYXZpZGEgbmVjLCBvcm5hcmUgdXQsIG1pLiBBZW5lYW4gdXQgb3JjaSB2ZWwgbWFzc2Egc3VzY2lwaXQgcHVsdmluYXIuIE51bGxhIHNvbGxpY2l0dWRpbi4gRnVzY2UgdmFyaXVzLCBsaWd1bGEgbm9uIHRlbXB1cyBhbGlxdWFtLCBudW5jIHR1cnBpcyB1bG";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:21;}s:4:"data";s:274:"xhbWNvcnBlciBuaWJoLCBpbiB0ZW1wdXMgc2FwaWVuIGVyb3Mgdml0YWUgbGlndWxhLiBQZWxsZW50ZXNxdWUgcmhvbmN1cyBudW5jIGV0IGF1Z3VlLiBJbnRlZ2VyIGlkIGZlbGlzLiBDdXJhYml0dXIgYWxpcXVldCBwZWxsZW50ZXNxdWUgZGlhbS4gSW50ZWdlciBxdWlzIG1ldHVzIHZpdGFlIGVsaXQgbG9ib3J0aXMgZWdlc3Rhcy4gTG9yZW0gaXBzdW0gZG9s";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:22;}s:4:"data";s:274:"b3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIE1vcmJpIHZlbCBlcmF0IG5vbiBtYXVyaXMgY29udmFsbGlzIHZlaGljdWxhLiBOdWxsYSBldCBzYXBpZW4uIEludGVnZXIgdG9ydG9yIHRlbGx1cywgYWxpcXVhbSBmYXVjaWJ1cywgY29udmFsbGlzIGlkLCBjb25ndWUgZXUsIHF1YW0uIE1hdXJpcyB1bGxhbWNvcnBlciBmZWxpcyB2aX";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:25;}s:4:"data";s:274:"RhZSBlcmF0LiBQcm9pbiBmZXVnaWF0LCBhdWd1ZSBub24gZWxlbWVudHVtIHBvc3VlcmUsIG1ldHVzIHB1cnVzIGlhY3VsaXMgbGVjdHVzLCBldCB0cmlzdGlxdWUgbGlndWxhIGp1c3RvIHZpdGFlIG1hZ25hLlxuQWxpcXVhbSBjb252YWxsaXMgc29sbGljaXR1ZGluIHB1cnVzLiBQcmFlc2VudCBhbGlxdWFtLCBlbmltIGF0IGZlcm1lbnR1bSBtb2xsaXMsIGxp";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:26;}s:4:"data";s:274:"Z3VsYSBtYXNzYSBhZGlwaXNjaW5nIG5pc2wsIGFjIGV1aXNtb2QgbmliaCBuaXNsIGV1IGxlY3R1cy4gRnVzY2UgdnVscHV0YXRlIHNlbSBhdCBzYXBpZW4uIFZpdmFtdXMgbGVvLiBBbGlxdWFtIGV1aXNtb2QgbGliZXJvIGV1IGVuaW0uIE51bGxhIG5lYyBmZWxpcyBzZWQgbGVvIHBsYWNlcmF0IGltcGVyZGlldC4gQWVuZWFuIHN1c2NpcGl0IG51bGxhIGluIG";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:28;}s:4:"data";s:274:"p1c3RvLiBTdXNwZW5kaXNzZSBjdXJzdXMgcnV0cnVtIGF1Z3VlLiBOdWxsYSB0aW5jaWR1bnQgdGluY2lkdW50IG1pLiBDdXJhYml0dXIgaWFjdWxpcywgbG9yZW0gdmVsIHJob25jdXMgZmF1Y2lidXMsIGZlbGlzIG1hZ25hIGZlcm1lbnR1bSBhdWd1ZSwgZXQgdWx0cmljaWVzIGxhY3VzIGxvcmVtIHZhcml1cyBwdXJ1cy4gQ3VyYWJpdHVyIGV1IGFtZXRcbiI=";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:4;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"e5a00d17fdf9193553d3201f96594ed5ebf28c1932c1a19057863f67a4525972";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file +O:30:"Qroques\ResilientData\Fragment":3:{s:10:"dataChunks";O:32:"Qroques\ResilientData\Collection":1:{s:5:"items";a:6:{i:0;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:19;}s:4:"data";s:274:"biBkaWFtIHNvZGFsZXMgaGVuZHJlcml0LgpVdCB2ZWxpdCBtYXVyaXMsIGVnZXN0YXMgc2VkLCBncmF2aWRhIG5lYywgb3JuYXJlIHV0LCBtaS4gQWVuZWFuIHV0IG9yY2kgdmVsIG1hc3NhIHN1c2NpcGl0IHB1bHZpbmFyLiBOdWxsYSBzb2xsaWNpdHVkaW4uIEZ1c2NlIHZhcml1cywgbGlndWxhIG5vbiB0ZW1wdXMgYWxpcXVhbSwgbnVuYyB0dXJwaXMgdWxsYW";}i:1;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:21;}s:4:"data";s:274:"1jb3JwZXIgbmliaCwgaW4gdGVtcHVzIHNhcGllbiBlcm9zIHZpdGFlIGxpZ3VsYS4gUGVsbGVudGVzcXVlIHJob25jdXMgbnVuYyBldCBhdWd1ZS4gSW50ZWdlciBpZCBmZWxpcy4gQ3VyYWJpdHVyIGFsaXF1ZXQgcGVsbGVudGVzcXVlIGRpYW0uIEludGVnZXIgcXVpcyBtZXR1cyB2aXRhZSBlbGl0IGxvYm9ydGlzIGVnZXN0YXMuIExvcmVtIGlwc3VtIGRvbG9y";}i:2;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:22;}s:4:"data";s:274:"IHNpdCBhbWV0LCBjb25zZWN0ZXR1ZXIgYWRpcGlzY2luZyBlbGl0LiBNb3JiaSB2ZWwgZXJhdCBub24gbWF1cmlzIGNvbnZhbGxpcyB2ZWhpY3VsYS4gTnVsbGEgZXQgc2FwaWVuLiBJbnRlZ2VyIHRvcnRvciB0ZWxsdXMsIGFsaXF1YW0gZmF1Y2lidXMsIGNvbnZhbGxpcyBpZCwgY29uZ3VlIGV1LCBxdWFtLiBNYXVyaXMgdWxsYW1jb3JwZXIgZmVsaXMgdml0YW";}i:3;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:25;}s:4:"data";s:274:"UgZXJhdC4gUHJvaW4gZmV1Z2lhdCwgYXVndWUgbm9uIGVsZW1lbnR1bSBwb3N1ZXJlLCBtZXR1cyBwdXJ1cyBpYWN1bGlzIGxlY3R1cywgZXQgdHJpc3RpcXVlIGxpZ3VsYSBqdXN0byB2aXRhZSBtYWduYS4KQWxpcXVhbSBjb252YWxsaXMgc29sbGljaXR1ZGluIHB1cnVzLiBQcmFlc2VudCBhbGlxdWFtLCBlbmltIGF0IGZlcm1lbnR1bSBtb2xsaXMsIGxpZ3Vs";}i:4;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:26;}s:4:"data";s:274:"YSBtYXNzYSBhZGlwaXNjaW5nIG5pc2wsIGFjIGV1aXNtb2QgbmliaCBuaXNsIGV1IGxlY3R1cy4gRnVzY2UgdnVscHV0YXRlIHNlbSBhdCBzYXBpZW4uIFZpdmFtdXMgbGVvLiBBbGlxdWFtIGV1aXNtb2QgbGliZXJvIGV1IGVuaW0uIE51bGxhIG5lYyBmZWxpcyBzZWQgbGVvIHBsYWNlcmF0IGltcGVyZGlldC4gQWVuZWFuIHN1c2NpcGl0IG51bGxhIGluIGp1c3";}i:5;O:31:"Qroques\ResilientData\DataChunk":2:{s:10:"identifier";O:41:"Qroques\ResilientData\DataChunkIdentifier":1:{s:5:"value";i:28;}s:4:"data";s:266:"RvLiBTdXNwZW5kaXNzZSBjdXJzdXMgcnV0cnVtIGF1Z3VlLiBOdWxsYSB0aW5jaWR1bnQgdGluY2lkdW50IG1pLiBDdXJhYml0dXIgaWFjdWxpcywgbG9yZW0gdmVsIHJob25jdXMgZmF1Y2lidXMsIGZlbGlzIG1hZ25hIGZlcm1lbnR1bSBhdWd1ZSwgZXQgdWx0cmljaWVzIGxhY3VzIGxvcmVtIHZhcml1cyBwdXJ1cy4gQ3VyYWJpdHVyIGV1IGFtZXQK";}}}s:10:"identifier";O:40:"Qroques\ResilientData\FragmentIdentifier":1:{s:5:"value";i:4;}s:8:"manifest";O:30:"Qroques\ResilientData\Manifest":2:{s:17:"resilientDataHash";O:26:"Qroques\ResilientData\Hash":1:{s:4:"hash";s:64:"ccec74f22f298deb6bc62053b4043839561ea1a08650e7d79f798b6e018202a6";}s:22:"splittingConfiguration";O:44:"Qroques\ResilientData\SplittingConfiguration":2:{s:17:"numberOfFragments";i:5;s:14:"acceptableLoss";i:2;}}} \ No newline at end of file diff --git a/tests/fixtures/image.png b/tests/fixtures/image.png new file mode 100644 index 0000000..cac66fc Binary files /dev/null and b/tests/fixtures/image.png differ diff --git a/tests/integration/SplitThenMergeTest.php b/tests/integration/SplitThenMergeTest.php index 723f457..188e6b4 100644 --- a/tests/integration/SplitThenMergeTest.php +++ b/tests/integration/SplitThenMergeTest.php @@ -17,10 +17,10 @@ #[CoversNothing] class SplitThenMergeTest extends TestCase { - public function testSplitThenMerge() + public function testSplitThenMergeTextFile() { $data = file_get_contents('tests/fixtures/lorem.txt'); - $resilientData = new ResilientData($data); + $resilientData = ResilientData::fromFile('tests/fixtures/lorem.txt'); $splittingConfiguration = new SplittingConfiguration(7, 3); $splitter = new Splitter(); $fragments = $splitter->split($resilientData, $splittingConfiguration); @@ -29,4 +29,29 @@ public function testSplitThenMerge() $reassembledResilientData = $assembler->assemble($fragments); $this->assertEquals($data, $reassembledResilientData->getData()); } + + public function testSplitThenMergeImageFile() + { + $data = file_get_contents('tests/fixtures/image.png'); + $resilientData = ResilientData::fromFile('tests/fixtures/image.png'); + $splittingConfiguration = new SplittingConfiguration(7, 3); + $splitter = new Splitter(); + $fragments = $splitter->split($resilientData, $splittingConfiguration); + + $assembler = new Assembler(); + $reassembledResilientData = $assembler->assemble($fragments); + $this->assertEquals($data, $reassembledResilientData->getData()); + } + + public function testSplitThenMergeText() + { + $resilientData = ResilientData::fromString('Lorem ipsum dolor sit amet, consectetur adipiscing elit.'); + $splittingConfiguration = new SplittingConfiguration(7, 3); + $splitter = new Splitter(); + $fragments = $splitter->split($resilientData, $splittingConfiguration); + + $assembler = new Assembler(); + $reassembledResilientData = $assembler->assemble($fragments); + $this->assertEquals('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', $reassembledResilientData->getData()); + } } diff --git a/tests/unit/AssemblerTest.php b/tests/unit/AssemblerTest.php index 0d0836c..f61492c 100644 --- a/tests/unit/AssemblerTest.php +++ b/tests/unit/AssemblerTest.php @@ -25,10 +25,10 @@ class AssemblerTest extends TestCase public function testAssemble(): void { $assembler = new Assembler(); - $chunk3 = new DataChunk(new DataChunkIdentifier(3), 'IlRoaXMg'); - $chunk5 = new DataChunk(new DataChunkIdentifier(5), 'aXMgYSBk'); - $chunk6 = new DataChunk(new DataChunkIdentifier(6), 'YXRhISI='); - $manifest = new Manifest(Hash::fromContent(base64_encode(json_encode('This is a data!'))), new SplittingConfiguration(3, 1)); + $chunk3 = new DataChunk(new DataChunkIdentifier(3), 'VGhpcyB'); + $chunk5 = new DataChunk(new DataChunkIdentifier(5), 'pcyBhIG'); + $chunk6 = new DataChunk(new DataChunkIdentifier(6), 'RhdGEh'); + $manifest = new Manifest(Hash::fromContent(base64_encode('This is a data!')), new SplittingConfiguration(3, 1)); $fragment0 = new Fragment(new FragmentIdentifier(0), $manifest, [$chunk3, $chunk5]); $fragment1 = new Fragment(new FragmentIdentifier(1), $manifest, [$chunk3, $chunk6]); @@ -50,9 +50,9 @@ public function testAssemble(): void public function testAssembleWithMissingData(): void { $assembler = new Assembler(); - $chunk3 = new DataChunk(new DataChunkIdentifier(3), 'IlRoaXMg'); - $chunk5 = new DataChunk(new DataChunkIdentifier(5), 'aXMgYSBk'); - $chunk6 = new DataChunk(new DataChunkIdentifier(6), 'YXRhISI='); + $chunk3 = new DataChunk(new DataChunkIdentifier(3), 'VGhpcyB'); + $chunk5 = new DataChunk(new DataChunkIdentifier(5), 'pcyBhIG'); + $chunk6 = new DataChunk(new DataChunkIdentifier(6), 'RhdGEh'); $manifest = new Manifest(Hash::fromContent(base64_encode(json_encode('This is a data!'))), new SplittingConfiguration(3, 1)); $fragment0 = new Fragment(new FragmentIdentifier(0), $manifest, [$chunk3, $chunk5]); diff --git a/tests/unit/SplitterTest.php b/tests/unit/SplitterTest.php index ec2f8ea..0161630 100644 --- a/tests/unit/SplitterTest.php +++ b/tests/unit/SplitterTest.php @@ -19,7 +19,7 @@ class SplitterTest extends TestCase public function testSplit(): void { $splitter = new Splitter(); - $resilientData = new ResilientData('12345'); + $resilientData = ResilientData::fromString('Lorem ipsum dolor sit amet, consectetur adipiscing elit.'); $fragments = $splitter->split($resilientData, new SplittingConfiguration(5, 2)); $this->assertCount(5, $fragments); }