Codebase list sugar-read-activity / 5b26f53
Fix fail to resume PDF After 72b4af8 ("Port to Python 3") the activity fails to resume PDF files. Traceback (most recent call last): File "/home/guest/Activities/Read.activity/readactivity.py", line 99, in get_md5 buf = fh.read(4096) File "/usr/lib/python3.7/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte Cause is opening the file as text, yet the file is not text. Fix is to open as binary. Thanks to Swarup for identifying an alternative solution that generated incorrect md5sums. Fixes https://github.com/sugarlabs/read-activity/issues/36 James Cameron 4 years ago
1 changed file(s) with 2 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
9292 def get_md5(filename):
9393 # FIXME: Should be moved somewhere else
9494 filename = filename.replace('file://', '') # XXX: hack
95 fh = open(filename)
95 fh = open(filename, 'rb')
9696 digest = hashlib.md5()
9797 while 1:
9898 buf = fh.read(4096)
99 if buf == "":
99 if buf == b'':
100100 break
101101 digest.update(buf)
102102 fh.close()