import os,sys,time,mmap,zlib PAGESIZE = 4096 SIZES = ((2**32) + PAGESIZE + 4, 0) FILE = 'py-mmap-testfile' print('Start:', time.gmtime()) for i in SIZES: if i == 0: break print('Testing file size ', str(i), ': ', sep='', end='') sys.stdout.flush() with open(FILE, "wb+") as f: f.seek(i-4) f.write(b'abcd') f.flush() sb = os.stat(FILE) if sb.st_size != i: print('size failure:', sb.st_size, ' != ', i, sep='', end='') sys.stdout.flush() mem = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) if mem[0] != ord('\0'): print('offset 0 failed: ', ord(mem[0]), ' ', end='', sep='') else: print('offset 0 ok ', end='', sep='') sys.stdout.flush() if mem[i-4] != ord('a'): print('offset i-4 failed: ', ord(mem[i-4]), ' ', end='', sep='') else: print('offset i-4 ok ', end='', sep='') print('[ALL IN ORDER] ', sep='', end='') sys.stdout.flush() for j in range(0, sb.st_size): y = mem[j] print('ok') sys.stdout.flush() os.unlink(FILE) print('End:', time.gmtime())