##// END OF EJS Templates
util: add an mmapread method...
Mark Thomas -
r34296:3bb2a9f2 default
parent child Browse files
Show More
@@ -26,6 +26,7 b' import errno'
26 import gc
26 import gc
27 import hashlib
27 import hashlib
28 import imp
28 import imp
29 import mmap
29 import os
30 import os
30 import platform as pyplatform
31 import platform as pyplatform
31 import re as remod
32 import re as remod
@@ -407,6 +408,17 b' class bufferedinputpipe(object):'
407 self._lenbuf += len(data)
408 self._lenbuf += len(data)
408 self._buffer.append(data)
409 self._buffer.append(data)
409
410
411 def mmapread(fp):
412 try:
413 fd = getattr(fp, 'fileno', lambda: fp)()
414 return mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
415 except ValueError:
416 # Empty files cannot be mmapped, but mmapread should still work. Check
417 # if the file is empty, and if so, return an empty buffer.
418 if os.fstat(fd).st_size == 0:
419 return ''
420 raise
421
410 def popen2(cmd, env=None, newlines=False):
422 def popen2(cmd, env=None, newlines=False):
411 # Setting bufsize to -1 lets the system decide the buffer size.
423 # Setting bufsize to -1 lets the system decide the buffer size.
412 # The default for bufsize is 0, meaning unbuffered. This leads to
424 # The default for bufsize is 0, meaning unbuffered. This leads to
General Comments 0
You need to be logged in to leave comments. Login now