File tree Expand file tree Collapse file tree 1 file changed +22
-9
lines changed Expand file tree Collapse file tree 1 file changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -68,26 +68,39 @@ def read(self, n):
68
68
if n == 0 or self ._current_pane == - 1 :
69
69
return _empty_view
70
70
value = None
71
- while n > 0 and self ._current_pane >= 0 :
71
+ is_memoryview = False
72
+ offset = 0
73
+
74
+ to_read = n
75
+ while to_read > 0 and self ._current_pane >= 0 :
72
76
p , q = self ._panes [self ._current_pane ]
73
77
size = q - p
74
78
remaining = size - self ._current_offset
75
79
start = p + self ._current_offset
76
- if n <= remaining :
77
- end = start + n
78
- if n < remaining :
79
- self ._current_offset += n
80
+ if to_read <= remaining :
81
+ end = start + to_read
82
+ if to_read < remaining :
83
+ self ._current_offset += to_read
80
84
else :
81
85
self ._next_pane ()
82
86
else :
83
87
end = q
84
88
self ._next_pane ()
89
+
90
+ read = end - start
85
91
if value :
86
- value .extend (self ._view [start :end ])
92
+ if is_memoryview :
93
+ new_value = bytearray (n )
94
+ new_value [:offset ] = value [:offset ]
95
+ value = new_value
96
+ is_memoryview = False
97
+ value [offset :offset + read ] = self ._view [start :end ]
87
98
else :
88
- value = bytearray (self ._view [start :end ])
89
- n -= end - start
90
- return memoryview (value )
99
+ value = memoryview (self ._view [start :end ])
100
+ is_memoryview = True
101
+ offset += read
102
+ to_read -= read
103
+ return value
91
104
92
105
93
106
class ChunkedInputBuffer (object ):
You can’t perform that action at this time.
0 commit comments