[docs]defget_file_size(path:Path)->int:"""Get file size in bytes."""returnpath.stat().st_size
[docs]defcompress_file(source:Path,target:Path)->None:"""Compress file using zlib."""withopen(source,"rb")assf,open(target,"wb")astf:tf.write(zlib.compress(sf.read()))
[docs]defdecompress_file(source:Path,target:Path)->None:"""Decompress file using zlib."""withopen(source,"rb")assf,open(target,"wb")astf:tf.write(zlib.decompress(sf.read()))
[docs]defcopy_or_move(source:Path,target:Path,rname:str,action:Literal["copy","move","asis"]="copy",compress:bool=False)->None:"""Copy or move a resource."""ifactionnotin["copy","move","asis"]:raiseValueError(f"Invalid action: {action}")try:ifaction=="copy":ifcompress:compress_file(source,target)else:copy2(source,target)elifaction=="move":ifcompress:compress_file(source,target)source.unlink()else:move(str(source),target)elifaction=="asis":passexceptExceptionase:raiseException(f"Failed to store resource '{rname}' from '{source}' to '{target}'")frome