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.
This commit is contained in:
Mike Fährmann
2017-10-25 15:04:45 +02:00
parent 239d7afea7
commit 9a41002b77
2 changed files with 8 additions and 9 deletions

View File

@@ -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():