##// END OF EJS Templates
mmap: add a size argument to mmapread...
marmoute -
r44487:8ed8dfbe default
parent child Browse files
Show More
@@ -415,10 +415,16 b' class bufferedinputpipe(object):'
415 return data
415 return data
416
416
417
417
418 def mmapread(fp):
418 def mmapread(fp, size=None):
419 if size == 0:
420 # size of 0 to mmap.mmap() means "all data"
421 # rather than "zero bytes", so special case that.
422 return b''
423 elif size is None:
424 size = 0
419 try:
425 try:
420 fd = getattr(fp, 'fileno', lambda: fp)()
426 fd = getattr(fp, 'fileno', lambda: fp)()
421 return mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
427 return mmap.mmap(fd, size, access=mmap.ACCESS_READ)
422 except ValueError:
428 except ValueError:
423 # Empty files cannot be mmapped, but mmapread should still work. Check
429 # Empty files cannot be mmapped, but mmapread should still work. Check
424 # if the file is empty, and if so, return an empty buffer.
430 # if the file is empty, and if so, return an empty buffer.
General Comments 0
You need to be logged in to leave comments. Login now