Mercurial > ec-dotfiles
annotate bin/ed2k @ 742:3b001c615c36
[setup] Fix mkdir on wrong directory
| author | nanaya <me@nanaya.net> |
|---|---|
| date | Mon, 03 Feb 2025 18:28:41 +0900 |
| parents | bcdf320dabf4 |
| children | 8d3ad5ae1ce4 |
| rev | line source |
|---|---|
| 719 | 1 #!/usr/bin/env php |
| 2 <?php | |
| 3 | |
| 4 function ed2k_hash(string $path): string | |
| 5 { | |
| 6 // ed2k hash is an md4 hash of concatenated binary md4 hashes of 9500 KiB file chunks. | |
| 7 static $bs = 9500 * 1024; | |
| 8 $hash = ''; | |
| 9 $fp = fopen($path, 'rb'); | |
|
4
94ee419ad047
Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
10 |
| 719 | 11 while (!feof($fp)) { |
| 12 $hash .= hash('md4', fread($fp, $bs), true); | |
| 13 } | |
| 14 fclose($fp); | |
| 15 | |
| 16 return hash('md4', $hash); | |
| 17 } | |
|
4
94ee419ad047
Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
18 |
| 719 | 19 for ($i = 1; $i < $argc; $i++) { |
| 20 $path = $argv[$i]; | |
| 21 $hash = ed2k_hash($path); | |
| 22 $filename = basename($path); | |
| 23 $filesize = filesize($path); | |
| 24 | |
| 25 echo "ed2k://|file|{$filename}|{$filesize}|{$hash}|"; | |
| 26 echo PHP_EOL; | |
| 27 } |
