fix partial downloads for 'text:' URLs

Using a filesize in bytes as offset into a Python string is not
a good idea if said file contains non-ASCII characters.
pull/54/head
Mike Fährmann 7 years ago
parent 239d7afea7
commit 9a41002b77
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -16,7 +16,6 @@ import logging
class DownloaderBase():
"""Base class for downloaders"""
retries = 1
mode = "b"
part = True
def __init__(self, session, output):
@ -66,13 +65,13 @@ class DownloaderBase():
# check response
if not offset:
mode = "w" + self.mode
mode = "wb"
if filesize:
self.log.info("Unable to resume partial download")
elif offset == -1:
break # early finish
else:
mode = "a" + self.mode
mode = "ab"
self.log.info("Resuming download at byte %d", offset)
# set missing filename extension

@ -14,21 +14,21 @@ from .. import config
class Downloader(DownloaderBase):
part = config.interpolate(("downloader", "text", "part"), True)
mode = "t"
def __init__(self, session, output):
DownloaderBase.__init__(self, session, output)
self.text = ""
self.content = b""
def connect(self, url, offset):
self.text = url[offset + 5:]
return offset, len(url) - 5
data = url.encode()
self.content = data[offset + 5:]
return offset, len(data) - 5
def receive(self, file):
file.write(self.text)
file.write(self.content)
def reset(self):
self.text = ""
self.content = b""
@staticmethod
def get_extension():

Loading…
Cancel
Save