Show More
@@ -52,14 +52,14 class httprangereader: | |||||
52 | def seek(self, pos): |
|
52 | def seek(self, pos): | |
53 | self.pos = pos |
|
53 | self.pos = pos | |
54 |
|
54 | |||
55 |
def read(self, |
|
55 | def read(self, n: int = -1): | |
56 | req = urlreq.request(pycompat.strurl(self.url)) |
|
56 | req = urlreq.request(pycompat.strurl(self.url)) | |
57 | end = '' |
|
57 | end = '' | |
58 |
|
58 | |||
59 |
if |
|
59 | if n == 0: | |
60 | return b'' |
|
60 | return b'' | |
61 |
elif |
|
61 | elif n > 0: | |
62 |
end = "%d" % (self.pos + |
|
62 | end = "%d" % (self.pos + n - 1) | |
63 | if self.pos or end: |
|
63 | if self.pos or end: | |
64 | req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) |
|
64 | req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) | |
65 |
|
65 | |||
@@ -79,14 +79,14 class httprangereader: | |||||
79 | if code == 200: |
|
79 | if code == 200: | |
80 | # HTTPRangeHandler does nothing if remote does not support |
|
80 | # HTTPRangeHandler does nothing if remote does not support | |
81 | # Range headers and returns the full entity. Let's slice it. |
|
81 | # Range headers and returns the full entity. Let's slice it. | |
82 |
if |
|
82 | if n > 0 and (self.pos + n) < len(data): | |
83 |
data = data[self.pos : self.pos + |
|
83 | data = data[self.pos : self.pos + n] | |
84 | elif self.pos < len(data): |
|
84 | elif self.pos < len(data): | |
85 | data = data[self.pos :] |
|
85 | data = data[self.pos :] | |
86 | else: |
|
86 | else: | |
87 | data = b'' |
|
87 | data = b'' | |
88 |
elif 0 < |
|
88 | elif 0 < n < len(data): | |
89 |
data = data[: |
|
89 | data = data[:n] | |
90 | self.pos += len(data) |
|
90 | self.pos += len(data) | |
91 | return data |
|
91 | return data | |
92 |
|
92 |
General Comments 0
You need to be logged in to leave comments.
Login now