cryptgeon/test/files.ts

21 lines
541 B
TypeScript
Raw Permalink Normal View History

2024-08-25 20:22:13 +00: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
}