Files
NapCatQQ/src/core/packet/utils/crypto/hash.ts
T
2024-10-16 11:58:47 +08:00

17 lines
597 B
TypeScript

// love from https://github.com/LagrangeDev/lagrangejs & https://github.com/takayama-lily/oicq
import * as crypto from 'crypto';
import * as stream from 'stream';
import * as fs from 'fs';
function sha1Stream(readable: stream.Readable) {
return new Promise((resolve, reject) => {
readable.on('error', reject);
readable.pipe(crypto.createHash('sha1').on('error', reject).on('data', resolve));
}) as Promise<Buffer>;
}
export function calculateSha1(filePath: string): Promise<Buffer> {
const readable = fs.createReadStream(filePath);
return sha1Stream(readable);
}