-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipfs-same.js
53 lines (46 loc) · 1.02 KB
/
ipfs-same.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var shell = WScript.CreateObject("WScript.Shell");
var hashes = {}
var copys_size = 0;
function search_hashes(hash)
{
WScript.StdOut.Write(hash + "\t\t\t\r");
var ipfs = shell.Exec("ipfs object links " + hash);
var stream = ipfs.StdOut;
var hash_list = [];
while(!stream.AtEndOfStream)
{
var line = stream.ReadLine();
if (line)
{
var hash = line.split(" ");
hash_list.push(hash);
}
}
for (var i = 0; i < hash_list.length; i++)
{
var hash = hash_list[i][0];
var size = hash_list[i][1];
if (!hashes[hash])
{
if ((/^Qm/).test(hash))
search_hashes(hash);
hashes[hash] = 1;
}
else
{
hashes[hash]++;
copys_size += +size;
WScript.Echo(hash, hashes[hash], size, "(Copy size: " + copys_size + " )")
}
}
}
function main()
{
if (WScript.Arguments.Length >= 1)
{
for (var i = 0; i < WScript.Arguments.Length; i++)
search_hashes(WScript.Arguments.Item(i));
WScript.Echo("Copy size:", copys_size, "\t\t\t\t\t");
}
}
main()