Skip to content

Commit b317b19

Browse files
author
Antoine Pecoraro
committed
feat(file_utils): mmap opening mode is now overridable
1 parent 373085b commit b317b19

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

unblob/file_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def from_bytes(cls, content: bytes):
2929
return m
3030

3131
@classmethod
32-
def from_path(cls, path: Path):
33-
with path.open("rb") as base_file:
34-
return cls(base_file.fileno(), 0, access=mmap.ACCESS_READ)
32+
def from_path(cls, path: Path, access=mmap.ACCESS_READ):
33+
mode = "r+b" if access == mmap.ACCESS_WRITE else "rb"
34+
with path.open(mode) as base_file:
35+
return cls(base_file.fileno(), 0, access=access)
3536

3637
def seek(self, pos: int, whence: int = os.SEEK_SET) -> int:
3738
try:

0 commit comments

Comments
 (0)