Skip to content

Commit

Permalink
Faster checksum calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Sep 1, 2023
1 parent 181c1cb commit f53e988
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Service/BookFileSystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class BookFileSystemManager
'*.epub','*.cbr','*.cbz','*.pdf','*.mobi'
];

public const CHUNK = 65536;

public KernelInterface $appKernel;
private SluggerInterface $slugger;

Expand Down Expand Up @@ -100,10 +102,14 @@ public function getCoverFile(Book $book): ?SplFileInfo
*/
public function getFileChecksum(SplFileInfo $file): string
{
$checkSum = sha1_file($file->getRealPath());
if($checkSum===false){
throw new \RuntimeException('Could not calculate file Checksum');
$checkSum = shell_exec('sha1sum -b ' . escapeshellarg($file->getRealPath()));

if ($checkSum === null || $checkSum === false) {
throw new RuntimeException('Could not calculate file Checksum');
}

[$checkSum,] = explode(' ', $checkSum);

return $checkSum;
}

Expand Down

0 comments on commit f53e988

Please sign in to comment.