Stream a file through sha256 and return the base64url digest + byte size.
(filePath: string)
| 220 | |
| 221 | /** Stream a file through sha256 and return the base64url digest + byte size. */ |
| 222 | function hashFile(filePath: string): Promise<{ hash: string; size: number }> { |
| 223 | return new Promise((resolve, reject) => { |
| 224 | const h = createHash('sha256'); |
| 225 | let size = 0; |
| 226 | const stream = createReadStream(filePath); |
| 227 | stream.on('data', (chunk: Uint8Array) => { |
| 228 | size += chunk.length; |
| 229 | h.update(chunk); |
| 230 | }); |
| 231 | stream.on('error', reject); |
| 232 | stream.on('end', () => { |
| 233 | resolve({ hash: h.digest('base64url'), size }); |
| 234 | }); |
| 235 | }); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Append new file entries to a distribution's RECORD file. |
no test coverage detected