-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from openzim/stream_dl
Stream files downloads to not exhaust memory
- Loading branch information
Showing
4 changed files
with
37 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import logging | ||
|
||
from zimscraperlib.logging import getLogger | ||
|
||
EXIT_CODE_WARC2ZIM_CHECK_FAILED = 2 | ||
EXIT_CODE_CRAWLER_LIMIT_HIT = 11 | ||
NORMAL_WARC2ZIM_EXIT_CODE = 100 | ||
REQUESTS_TIMEOUT = 10 | ||
|
||
logger = getLogger(name="zimit", level=logging.INFO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pathlib import Path | ||
|
||
import requests | ||
|
||
from zimit.constants import REQUESTS_TIMEOUT | ||
|
||
|
||
def download_file(url: str, fpath: Path): | ||
"""Download file from url to fpath with streaming""" | ||
with requests.get(url, timeout=REQUESTS_TIMEOUT, stream=True) as resp: | ||
resp.raise_for_status() | ||
with open(fpath, "wb") as f: | ||
for chunk in resp.iter_content(chunk_size=8192): | ||
f.write(chunk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters