Skip to content

Commit

Permalink
Merge pull request #77 from rabernat/incremental-download
Browse files Browse the repository at this point in the history
use incremental downloading
  • Loading branch information
rabernat committed Feb 23, 2021
2 parents 556f063 + 12fa8c2 commit e2188f7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pangeo_forge/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,16 @@ def cache_input(self) -> Callable:
def cache_func(input_key: Hashable) -> None:
logger.info(f"Caching input {input_key}")
fname = self._inputs[input_key]
# TODO: add a check for whether the input is already cached?
with input_opener(fname, mode="rb", **self.fsspec_open_kwargs) as source:
with self.input_cache.open(fname, mode="wb") as target:
target.write(source.read())
# TODO: make this configurable? Would we ever want to change it?
BLOCK_SIZE = 10_000_000 # 10 MB
while True:
data = source.read(BLOCK_SIZE)
if not data:
break
target.write(data)

return cache_func

Expand Down

0 comments on commit e2188f7

Please sign in to comment.