DeaD_EyE icon

find holes in sparse files

DeaD_EyE | PRO | 06/06/25 09:36:57 AM UTC | 0 ⭐ | 1051 👁️ | Never ⏰ | []
Python |

540 B

|

None

|

0 👍

/

0 👎

import os
 
 
def find_holes(file):
    with open(file, "rb") as fd:
        fileno = fd.fileno()
        size = os.stat(fileno).st_size
        pos = 0
        holes = []
 
        while True:
            hole_start = os.lseek(fileno, pos, os.SEEK_HOLE)
            data_start = os.lseek(fileno, pos, os.SEEK_DATA)
 
            if hole_start == size:
                break
 
            holes.append((hole_start, data_start))
 
            if pos == data_start:
                break
 
            pos = data_start
 
        return holes

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎