| 43 | |
| 44 | |
| 45 | def identity(path, executable=False): |
| 46 | path = Path(path).resolve(strict=True) |
| 47 | info = path.stat() |
| 48 | if not stat.S_ISREG(info.st_mode) or (executable and not os.access(str(path), os.X_OK)): |
| 49 | raise Infrastructure("invalid input file: " + str(path)) |
| 50 | digest = hashlib.sha256() |
| 51 | with path.open("rb") as stream: |
| 52 | for data in iter(lambda: stream.read(1024 * 1024), b""): |
| 53 | digest.update(data) |
| 54 | return {"path": str(path), "bytes": info.st_size, "sha256": digest.hexdigest()} |
| 55 | |
| 56 | |
| 57 | def drain(pipe, destination, state, stop): |