cryptgeon/test/files.ts

21 lines
541 B
TypeScript
Raw Normal View History

2024-08-25 22:22:13 +02:00
import { createHash } from 'node:crypto'
import { cp, readFile } from 'node:fs/promises'
export const Files = {
PDF: 'test/assets/AES.pdf',
Image: 'test/assets/image.jpg',
Zip: 'test/assets/Pigeons.zip',
}
export async function getFileChecksum(file: string) {
const buffer = await readFile(file)
const hash = createHash('sha3-256').update(buffer).digest('hex')
return hash
}
export async function tmpFile(file: string) {
const name = `./tmp/${Math.random().toString(36).substring(7)}`
await cp(file, name)
return name
}