import SparkMD5 from "spark-md5";

export default async function(file:any):Promise<any>{
    const ab = await file.arrayBuffer();
    // const fileMd5 = md5(Buffer.from(ab));
    const chunkSize = 104857600;
    const chunks = Math.ceil(file.size / chunkSize);
    let currentChunk = 0;
    const spark = new SparkMD5.ArrayBuffer();
    while(currentChunk<chunks){
        const start = currentChunk * chunkSize,
        end = start + chunkSize >= file.size ? file.size : start + chunkSize;
        spark.append(Buffer.from(ab).slice(start,end))
        currentChunk ++
    }
    // spark.append(Buffer.from(ab))
    return spark.end()
     
}