Created
March 20, 2023 16:36
-
-
Save gdlmx/5056eaf91e77d4d2c9895c4e15e9984e to your computer and use it in GitHub Desktop.
Create memory view of file larger than RAM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mmap | |
import zlib | |
import sys | |
from contextlib import contextmanager | |
@contextmanager | |
def f2bytes(fname): | |
with open(fname, 'rb') as f : | |
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m: | |
mmview = memoryview(m) | |
try: | |
yield mmview | |
finally: | |
mmview.release() | |
def main(fname): | |
with f2bytes(fname) as m: | |
return zlib.crc32(m) | |
if __name__ == '__main__': | |
n = sys.argv[1] | |
print(n,'crc32 =', hex(main(n))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment