You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While dealing with a filesystem error when unpacking a zip to a directory, I saw the comment "hopefully the directory is prior to any files inside it!" in line 198 in mod.ts.
In my case the directory entry for a file was missing completely. I could however still open the zip with any zip tool on my computer.
I created a solution with a helper function as shown:
import{dirname,resolve}from"https://deno.land/[email protected]/path/mod.ts";import{JSZip}from"https://deno.land/x/[email protected]/mod.ts";exportasyncfunctionunpackJSZip(zip: JSZip,dir="."){constcreatedDirs=newSet<string>();for(constfileEntryofzip){constfilePath=resolve(dir,fileEntry.name);constdirPath=fileEntry.dir ? filePath : dirname(filePath);if(!createdDirs.has(dirPath)){awaitDeno.mkdir(dirPath,{recursive: true});createdDirs.add(dirPath);}if(!fileEntry.dir){constcontent=awaitfileEntry.async("uint8array");// TODO pass WriteFileOptions e.g. modeawaitDeno.writeFile(filePath,content);}}}
This fixed the bug with a minimal performance penalty.
The text was updated successfully, but these errors were encountered:
After some further investigation I found out this is a problem with adding files, which have paths including backslashes. I therefore added a test for this.
Pretty much every zip tool, including unzip handles this by creating the directory. But in linux backslashes are allowed in filenames, which could mean breaking changes. On windows the unzip method in the current implementation fails in this case.
Furthermore, I suggest adding an option to the add file method, which controls if the backslahes in the filepath are replaced with forward slashes, since this produces warnings in linux' unzip.
All these changes are implemented in my following PR.
While dealing with a filesystem error when unpacking a zip to a directory, I saw the comment "hopefully the directory is prior to any files inside it!" in line 198 in mod.ts.
In my case the directory entry for a file was missing completely. I could however still open the zip with any zip tool on my computer.
I created a solution with a helper function as shown:
This fixed the bug with a minimal performance penalty.
The text was updated successfully, but these errors were encountered: