| 114 | |
| 115 | @dataclasses.dataclass |
| 116 | class Upload: |
| 117 | name: str |
| 118 | label: str | None |
| 119 | |
| 120 | def __post_init__(self): |
| 121 | self.hasher = hashlib.sha256() |
| 122 | if self.name == "SHA256SUMS": |
| 123 | self.contents = b"" |
| 124 | else: |
| 125 | self.contents = None |
| 126 | |
| 127 | def update(self, chunk: bytes) -> None: |
| 128 | self.hasher.update(chunk) |
| 129 | if self.contents is not None: |
| 130 | self.contents += chunk |
| 131 | |
| 132 | def to_asset(self) -> Asset: |
| 133 | return Asset(self.name, self.label, self.hasher.hexdigest(), self.contents) |
| 134 | |
| 135 | |
| 136 | @dataclasses.dataclass |