| 47 | |
| 48 | |
| 49 | def on_resource_concluded(resource): |
| 50 | if resource.status == RNS.Resource.COMPLETE: |
| 51 | # Resource.data may be a file-handle or bytes depending on size. |
| 52 | if hasattr(resource.data, "read"): |
| 53 | try: |
| 54 | resource.data.seek(0) |
| 55 | except Exception: |
| 56 | pass |
| 57 | data = resource.data.read() |
| 58 | else: |
| 59 | data = bytes(resource.data) if resource.data is not None else b"" |
| 60 | state["payload_bytes"] = data |
| 61 | state["payload_hash"] = hashlib.sha256(data).hexdigest() |
| 62 | state["received"] = True |
| 63 | print(f"[python] resource complete: {len(data)} bytes, sha256 {state['payload_hash']}", |
| 64 | flush=True) |
| 65 | else: |
| 66 | print(f"[python] resource failed with status {resource.status}", flush=True) |
| 67 | state["received"] = True # break the wait loop |
| 68 | |
| 69 | |
| 70 | def on_link_established(link): |