Copy the current file to the given destination. Args: dst: Target file. It can be any PathLike compatible path (e.g. `gs://...`) overwrite: Whether the file should be overwritten or not Returns: The new created file. Raises: FileExistsError: If `overwrite` is f
(
self,
dst: epath.PathLike,
overwrite: bool = False,
)
| 328 | return self.read_bytes().decode(encoding=encoding or 'utf-8') |
| 329 | |
| 330 | def copy( |
| 331 | self, |
| 332 | dst: epath.PathLike, |
| 333 | overwrite: bool = False, |
| 334 | ) -> epath.Path: |
| 335 | """Copy the current file to the given destination. |
| 336 | |
| 337 | Args: |
| 338 | dst: Target file. It can be any PathLike compatible path (e.g. `gs://...`) |
| 339 | overwrite: Whether the file should be overwritten or not |
| 340 | |
| 341 | Returns: |
| 342 | The new created file. |
| 343 | |
| 344 | Raises: |
| 345 | FileExistsError: If `overwrite` is false and destination exists. |
| 346 | """ |
| 347 | dst = epath.Path(dst) |
| 348 | if not overwrite and dst.exists(): |
| 349 | raise FileExistsError(f'Cannot copy {self}. Destination {dst} exists.') |
| 350 | # Otherwise, copy src to dst |
| 351 | dst.write_bytes(self.read_bytes()) |
| 352 | return dst |
| 353 | |
| 354 | |
| 355 | def _parse_github_path(path: str) -> Tuple[str, str, str]: |