summaryrefslogtreecommitdiffstats
path: root/contrib/python/fonttools/fontTools/misc/filesystem/_tools.py
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-07-31 11:14:11 +0300
committerrobot-piglet <[email protected]>2025-07-31 12:10:37 +0300
commite177928be72df9669dbb830824b4233a33c8723f (patch)
treea91d4ec6bbe7dc221c049475a91255c2996fd84e /contrib/python/fonttools/fontTools/misc/filesystem/_tools.py
parenta1700abf3c749b43117e757deb259d2a7bcdf46a (diff)
Intermediate changes
commit_hash:60aaacde4a6a0fb68b6435d7f100365d0c77d64d
Diffstat (limited to 'contrib/python/fonttools/fontTools/misc/filesystem/_tools.py')
-rw-r--r--contrib/python/fonttools/fontTools/misc/filesystem/_tools.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/contrib/python/fonttools/fontTools/misc/filesystem/_tools.py b/contrib/python/fonttools/fontTools/misc/filesystem/_tools.py
new file mode 100644
index 00000000000..4b02ac0d253
--- /dev/null
+++ b/contrib/python/fonttools/fontTools/misc/filesystem/_tools.py
@@ -0,0 +1,34 @@
+from __future__ import annotations
+
+import typing
+from pathlib import PurePosixPath
+
+from ._errors import DirectoryNotEmpty
+
+if typing.TYPE_CHECKING:
+ from typing import IO
+
+ from ._base import FS
+
+
+def remove_empty(fs: FS, path: str):
+ """Remove all empty parents."""
+ path = PurePosixPath(path)
+ root = PurePosixPath("/")
+ try:
+ while path != root:
+ fs.removedir(path.as_posix())
+ path = path.parent
+ except DirectoryNotEmpty:
+ pass
+
+
+def copy_file_data(src_file: IO, dst_file: IO, chunk_size: int | None = None):
+ """Copy data from one file object to another."""
+ _chunk_size = 1024 * 1024 if chunk_size is None else chunk_size
+ read = src_file.read
+ write = dst_file.write
+ # in iter(callable, sentilel), callable is called until it returns the sentinel;
+ # this allows to copy `chunk_size` bytes at a time.
+ for chunk in iter(lambda: read(_chunk_size) or None, None):
+ write(chunk)