Mercurial > ec-dotfiles
annotate bin/ed2k @ 727:49538e2aad65 default tip
Add a useful editrc
author | nanaya <me@nanaya.net> |
---|---|
date | Tue, 24 Sep 2024 16:58:15 +0900 |
parents | bcdf320dabf4 |
children |
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 } |