import { unzip } from "unzipit" ; import FileType from "file-type/browser" ; export const ZIP_MIMES = [ "application/zip" , "application/x-zip-compressed" , "multipart/x-zip" ] ; const naiveMimes = { "html" : "text/html" , "js" : "text/javascript" , "css" : "text/css" , "csv" : "text/csv" , } ; param filename export function getNaiveMimeType ( filename ) { const ext = filename . split ( '.' ) . pop ( ) ; return ( ext && naiveMimes [ ext ] ) || false ; } param file returns export async function unzipFile ( file ) { const { entries } = await unzip ( file ) ; const blobs = { } ; for ( const name in entries ) { let mime = getNaiveMimeType ( name ) ; if ( ! mime ) { const buffer = await entries [ name ] . arrayBuffer ( ) ; const type = await FileType . fromBuffer ( buffer ) ; if ( type ) { mime = type . mime ; } } blobs [ name ] = await entries [ name ] . blob ( mime || undefined ) ; } return blobs ; }