MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / _download

Function _download

diffusers/scripts/convert_consistency_decoder.py:43–78  ·  view source on GitHub ↗
(url: str, root: str)

Source from the content-addressed store, hash-verified

41
42
43def _download(url: str, root: str):
44 os.makedirs(root, exist_ok=True)
45 filename = os.path.basename(url)
46
47 expected_sha256 = url.split("/")[-2]
48 download_target = os.path.join(root, filename)
49
50 if os.path.exists(download_target) and not os.path.isfile(download_target):
51 raise RuntimeError(f"{download_target} exists and is not a regular file")
52
53 if os.path.isfile(download_target):
54 if insecure_hashlib.sha256(open(download_target, "rb").read()).hexdigest() == expected_sha256:
55 return download_target
56 else:
57 warnings.warn(f"{download_target} exists, but the SHA256 checksum does not match; re-downloading the file")
58
59 with urllib.request.urlopen(url) as source, open(download_target, "wb") as output:
60 with tqdm(
61 total=int(source.info().get("Content-Length")),
62 ncols=80,
63 unit="iB",
64 unit_scale=True,
65 unit_divisor=1024,
66 ) as loop:
67 while True:
68 buffer = source.read(8192)
69 if not buffer:
70 break
71
72 output.write(buffer)
73 loop.update(len(buffer))
74
75 if insecure_hashlib.sha256(open(download_target, "rb").read()).hexdigest() != expected_sha256:
76 raise RuntimeError("Model has been downloaded but the SHA256 checksum does not not match")
77
78 return download_target
79
80
81class ConsistencyDecoder:

Callers 1

__init__Method · 0.85

Calls 2

infoMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected