equal
deleted
inserted
replaced
447 # size of 0 to mmap.mmap() means "all data" |
447 # size of 0 to mmap.mmap() means "all data" |
448 # rather than "zero bytes", so special case that. |
448 # rather than "zero bytes", so special case that. |
449 return b'' |
449 return b'' |
450 elif size is None: |
450 elif size is None: |
451 size = 0 |
451 size = 0 |
|
452 fd = getattr(fp, 'fileno', lambda: fp)() |
452 try: |
453 try: |
453 fd = getattr(fp, 'fileno', lambda: fp)() |
|
454 return mmap.mmap(fd, size, access=mmap.ACCESS_READ) |
454 return mmap.mmap(fd, size, access=mmap.ACCESS_READ) |
455 except ValueError: |
455 except ValueError: |
456 # Empty files cannot be mmapped, but mmapread should still work. Check |
456 # Empty files cannot be mmapped, but mmapread should still work. Check |
457 # if the file is empty, and if so, return an empty buffer. |
457 # if the file is empty, and if so, return an empty buffer. |
458 if os.fstat(fd).st_size == 0: |
458 if os.fstat(fd).st_size == 0: |