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
92 | 92 | def get_md5(filename): |
93 | 93 | # FIXME: Should be moved somewhere else |
94 | 94 | filename = filename.replace('file://', '') # XXX: hack |
95 | fh = open(filename) | |
95 | fh = open(filename, 'rb') | |
96 | 96 | digest = hashlib.md5() |
97 | 97 | while 1: |
98 | 98 | buf = fh.read(4096) |
99 | if buf == "": | |
99 | if buf == b'': | |
100 | 100 | break |
101 | 101 | digest.update(buf) |
102 | 102 | fh.close() |