* Gets Sha256 from file * @param string $path the path of the file to hash * @return Future that resolves as the sha256 object * @throws FileDoesNotExistException if the file does not exist * @throws InvalidSha256Exception if the hash is invalid */
(string $path)
| 19 | * @throws InvalidSha256Exception if the hash is invalid |
| 20 | */ |
| 21 | public static function TryFromFile(string $path): Future |
| 22 | { |
| 23 | return async(function () use ($path) { |
| 24 | if (!file_exists($path)) { |
| 25 | throw new FileDoesNotExistException(); |
| 26 | } |
| 27 | |
| 28 | $hashString = hash_file("sha256", $path); |
| 29 | |
| 30 | if (Sha256::IsValid($hashString)->await()) { |
| 31 | $sha256 = new Sha256(); |
| 32 | $sha256->_hash = $hashString; |
| 33 | return $sha256; |
| 34 | } |
| 35 | |
| 36 | throw new InvalidSha256Exception(); |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Gets Sha256 from string |