3
from gi.repository import Gio
3
from gi.repository import Gio # pylint: disable-msg=E0611
9
""" FIXME Need to handle exceptions !! """
12
longlongformat = 'q' # long long
13
bytesize = struct.calcsize(longlongformat)
15
fp = Gio.File.new_for_uri (name)
17
file_info = fp.query_info ('standard::size', 0, None)
18
filesize = file_info.get_attribute_uint64 ('standard::size')
22
if filesize < 65536 * 2:
25
data = file(fp.get_path(), 'rb')
27
for x in range(65536/bytesize):
28
buffer = data.read(bytesize)
29
(l_value,)= struct.unpack(longlongformat, buffer)
31
hash = hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number
33
data.seek (max (0, filesize - 65536), os.SEEK_SET)
35
if data.tell() != max (0, filesize - 65536):
38
for x in range(65536/bytesize):
39
buffer = data.read(bytesize)
40
(l_value,)= struct.unpack(longlongformat, buffer)
42
hash = hash & 0xFFFFFFFFFFFFFFFF
45
returnedhash = "%016x" % hash
46
return returnedhash, filesize
9
""" FIXME Need to handle exceptions !! """
11
longlongformat = 'q' # long long
12
bytesize = struct.calcsize (longlongformat)
14
file_to_hash = Gio.File.new_for_uri (name)
16
file_info = file_to_hash.query_info ('standard::size', 0, None)
17
filesize = file_info.get_attribute_uint64 ('standard::size')
21
if filesize < 65536 * 2:
24
file_handle = file (file_to_hash.get_path (), "rb")
26
for _ in range (65536 / bytesize):
27
buf = file_handle.read (bytesize)
28
(l_value,) = struct.unpack (longlongformat, buf)
30
file_hash = file_hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number
32
file_handle.seek (max (0, filesize - 65536), os.SEEK_SET)
34
if file_handle.tell() != max (0, filesize - 65536):
37
for _ in range (65536/bytesize):
38
buf = file_handle.read (bytesize)
39
(l_value,) = struct.unpack (longlongformat, buf)
41
file_hash = file_hash & 0xFFFFFFFFFFFFFFFF
44
returnedhash = "%016x" % file_hash
49
return returnedhash, filesize