use iter to read file with a multiple of hash block_size(sha1sum)
This commit is contained in:
parent
7d712445bf
commit
5c6ff50027
1 changed files with 5 additions and 8 deletions
13
ox/file.py
13
ox/file.py
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
# GPL 2008
|
# GPL 2008
|
||||||
from __future__ import division
|
from __future__ import division, with_statement
|
||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
import re
|
import re
|
||||||
|
@ -86,12 +86,9 @@ def sha1sum(filename, cached=False):
|
||||||
if cached:
|
if cached:
|
||||||
return cache(filename, 'sha1')
|
return cache(filename, 'sha1')
|
||||||
sha1 = hashlib.sha1()
|
sha1 = hashlib.sha1()
|
||||||
file=open(filename)
|
with open(filename) as f:
|
||||||
buffer=file.read(4096)
|
for chunk in iter(lambda: f.read(128*sha1.block_size), ''):
|
||||||
while buffer:
|
sha1.update(chunk)
|
||||||
sha1.update(buffer)
|
|
||||||
buffer=file.read(4096)
|
|
||||||
file.close()
|
|
||||||
return sha1.hexdigest()
|
return sha1.hexdigest()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -235,7 +232,7 @@ def ffprobe(filename):
|
||||||
if not 'display_aspect_ratio' in v and 'width' in v:
|
if not 'display_aspect_ratio' in v and 'width' in v:
|
||||||
v['display_aspect_ratio'] = '%d:%d' % (v['width'], v['height'])
|
v['display_aspect_ratio'] = '%d:%d' % (v['width'], v['height'])
|
||||||
v['pixel_aspect_ratio'] = '1:1'
|
v['pixel_aspect_ratio'] = '1:1'
|
||||||
info['oshash'] = ox.oshash(filename)
|
info['oshash'] = oshash(filename)
|
||||||
info['path'] = os.path.basename(filename)
|
info['path'] = os.path.basename(filename)
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue