import { createHash } from "node:crypto"; export const HASH_HEAD_BYTES = 16 * 1024 * 1024; /** 文件头部 MD5(样本应已截到 16MB 内) */ export function headMd5(sample: Buffer): string { return createHash("md5").update(sample).digest("hex"); } /** 官方 match 要求 fileName 不含文件夹路径与扩展名;点开头的隐藏文件不算扩展名 */ export function matchFileName(path: string): string { const base = path.split("/").pop() ?? path; const dot = base.lastIndexOf("."); return dot > 0 ? base.slice(0, dot) : base; }