annotate bin/ed2k @ 725:0a896ffe3029

Switch to tgz bsdunzip doesn't seem to unzip from stdin.
author nanaya <me@nanaya.net>
date Mon, 19 Aug 2024 17:03:52 +0900
parents bcdf320dabf4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
719
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
1 #!/usr/bin/env php
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
2 <?php
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
3
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
4 function ed2k_hash(string $path): string
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
5 {
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
6 // ed2k hash is an md4 hash of concatenated binary md4 hashes of 9500 KiB file chunks.
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
7 static $bs = 9500 * 1024;
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
8 $hash = '';
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
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
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
11 while (!feof($fp)) {
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
12 $hash .= hash('md4', fread($fp, $bs), true);
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
13 }
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
14 fclose($fp);
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
15
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
16 return hash('md4', $hash);
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
17 }
4
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
18
719
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
19 for ($i = 1; $i < $argc; $i++) {
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
20 $path = $argv[$i];
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
21 $hash = ed2k_hash($path);
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
22 $filename = basename($path);
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
23 $filesize = filesize($path);
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
24
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
25 echo "ed2k://|file|{$filename}|{$filesize}|{$hash}|";
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
26 echo PHP_EOL;
bcdf320dabf4 Rewrite the ed2k again in php
nanaya <me@nanaya.net>
parents: 4
diff changeset
27 }