Mercurial > hgrepos > Python > apps > py-cutils
comparison shasum.py @ 58:ae5b31c10b41
Enhance comments
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 08 Feb 2022 20:31:25 +0100 |
| parents | 0fa2067bedb8 |
| children | b96d3585e8ce |
comparison
equal
deleted
inserted
replaced
| 57:0fa2067bedb8 | 58:ae5b31c10b41 |
|---|---|
| 468 pass | 468 pass |
| 469 fd = os.open(filename, flags) | 469 fd = os.open(filename, flags) |
| 470 try: | 470 try: |
| 471 st = os.fstat(fd) | 471 st = os.fstat(fd) |
| 472 filesize = st[stat.ST_SIZE] | 472 filesize = st[stat.ST_SIZE] |
| 473 # | |
| 474 # On Windows mmapped file with length 0 are not supported | |
| 475 # -> use low-level IO | |
| 476 # | |
| 477 if mmap is None: | 473 if mmap is None: |
| 474 # No mmmap available -> use traditional low-level file IO | |
| 478 while True: | 475 while True: |
| 479 buf = os.read(fd, CHUNK_SIZE) | 476 buf = os.read(fd, CHUNK_SIZE) |
| 480 if len(buf) == 0: | 477 if len(buf) == 0: |
| 481 break | 478 break |
| 482 h.update(buf) | 479 h.update(buf) |
| 483 else: | 480 else: |
| 484 # mmap | 481 # |
| 482 # Use mmap | |
| 483 # | |
| 484 # NOTE: On Windows mmapped files with length 0 are not supported. | |
| 485 # So ensure to not call mmap.mmap() if the file size is 0. | |
| 486 # | |
| 485 if filesize < MAP_CHUNK_SIZE: | 487 if filesize < MAP_CHUNK_SIZE: |
| 486 mapsize = filesize | 488 mapsize = filesize |
| 487 else: | 489 else: |
| 488 mapsize = MAP_CHUNK_SIZE | 490 mapsize = MAP_CHUNK_SIZE |
| 489 mapoffset = 0 | 491 mapoffset = 0 |
