aboutsummaryrefslogtreecommitdiffstats
path: root/python/sandcrawler/misc.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-11-08 13:20:24 -0800
committerBryan Newbold <bnewbold@archive.org>2020-11-08 13:20:26 -0800
commit3977afdff906367525cd6959221b6f3edf19793d (patch)
treec8284f463a65e47a854170ebf85c3f26a213643d /python/sandcrawler/misc.py
parente87f28d62e7e92de5502cd04d8c3effb19da19f8 (diff)
downloadsandcrawler-3977afdff906367525cd6959221b6f3edf19793d.tar.gz
sandcrawler-3977afdff906367525cd6959221b6f3edf19793d.zip
gen_file_metadata: allow empty/null bodies (if flag set)
This is for HTML sub-resources, which can validly be empty (I think)
Diffstat (limited to 'python/sandcrawler/misc.py')
-rw-r--r--python/sandcrawler/misc.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/python/sandcrawler/misc.py b/python/sandcrawler/misc.py
index 67e5c0b..1cdd038 100644
--- a/python/sandcrawler/misc.py
+++ b/python/sandcrawler/misc.py
@@ -18,13 +18,15 @@ def clean_url(s: str) -> str:
parsed.colon_before_port = b''
return str(urlcanon.whatwg(parsed))
-def gen_file_metadata(blob: bytes) -> dict:
+def gen_file_metadata(blob: bytes, allow_empty: bool = False) -> dict:
"""
Takes a file blob (bytestream) and returns hashes and other metadata.
Returns a dict: size_bytes, md5hex, sha1hex, sha256hex, mimetype
"""
- assert blob
+ assert blob is not None
+ if not allow_empty:
+ assert blob
mimetype = magic.Magic(mime=True).from_buffer(blob)
if mimetype in ("application/xml", "text/xml"):
# crude check for JATS XML, using only first 1 kB of file