Skip to content

Commit 01e40b5

Browse files
committed
Use memoryview instead of buffer
This uses memoryview by default, which is supported in Python 3 and Python 2.7, but not Python 2.6, and falls back to the old `buffer` type in Python 2.6 and when the memoryview does not support the type, such as when mmap instaces are passed in.
1 parent b881134 commit 01e40b5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

gitdb/stream.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ def read(self, size=-1):
270270
# END adjust winsize
271271

272272
# takes a slice, but doesn't copy the data, it says ...
273-
indata = buffer(self._m, self._cws, self._cwe - self._cws)
273+
try:
274+
indata = memoryview(self._m)[self._cws:self._cwe].tobytes()
275+
except (NameError, TypeError):
276+
indata = buffer(self._m, self._cws, self._cwe - self._cws)
274277

275278
# get the actual window end to be sure we don't use it for computations
276279
self._cwe = self._cws + len(indata)

0 commit comments

Comments
 (0)