Skip to content

C implementation with Python 3.7 bindings of the BCacheFS

License

Notifications You must be signed in to change notification settings

mila-iqia/bcachefs

Repository files navigation

Current PyPi Version Codecov Report Documentation Status

bcachefs

C implementation with Python 3.7+ bindings for Bcachefs

import bcachefs as bch

# Using a filesystem-like API
with bch.mount("disk.img") as bchfs:
    for root, dirs, files in bchfs.walk():
        print(f"Directories in {root}: {[str(d) for d in dirs]}")
        for ent in files:
            with image.open(ent, "rb") as f:
                for line in f.lines():
                    print(line)

# Using a cursor with entries cache
with bch.mount("disk.img").cd() as cursor:
    for root, dirs, files in cursor.walk():
        print(f"Directories in {root}: {[str(d) for d in dirs]}")
        for ent in files:
            with image.open(ent, "rb") as f:
                for line in f.lines():
                    print(line)

# Using a ZipFile-like API
with Bcachefs("disk.img", "r") as image:
    file_names = image.namelist()

    for filename in file_names:
        with image.open(filename, "rb") as f:
            for line in f.lines():
                print(line)