-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhasher.py
More file actions
32 lines (25 loc) · 692 Bytes
/
hasher.py
File metadata and controls
32 lines (25 loc) · 692 Bytes
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
#!/bin/python
import sys
import json
import hashlib
import struct
def getHashSize(physicalSize, metadata):
size = physicalSize
if ('meta' in metadata):
size = min(size, metadata['meta']['size'])
return size
input = sys.stdin
line = input.readline()
filesRead = 0
while line:
metadata = json.loads(line)
sizeData = input.read(8)
size = struct.unpack('<Q', sizeData)[0]
data = input.read(size)
size = getHashSize(size, metadata)
hasher = hashlib.md5()
hasher.update(data[:size])
print("%s\t%s\t%s\t%s" % (metadata['path'], metadata['name']['name'], str(size), hasher.hexdigest()))
filesRead += 1
line = input.readline()
print("read %s files" % (filesRead))