node-zip-stream
node-zip-stream copied to clipboard
How can I deal with different files with the same name and zip them?
I have three jpg files, and they have same name.
I deal with them like this:
archive.entry(filestream, { name: ${folderName + item.info.name} }, (err, entry) => { ... }
And the result is, I get a zip file, unarchive it, there is only one jpg.
Is there any options to avoid this?
BTW, the api documentation page is 404.
I faced a similar issue, and to avoid file name collisions I maintained a map(name, occurence) to keep a track of all file names
If I found a duplicate, I added a suffix 1, 2, 3 ...
function foo(folderName: string, items: Record<string, any>[], archive: any, filestream: any): void {
const fileNameMap = new Map<string, number>()
for(const item of items) {
const fileName = folderName + item.info.name
const occurenceTillNow = fileNameMap.get(fileName) ?? 0
fileNameMap.set(fileName, occurenceTillNow+1)
const suffix = occurenceTillNow===0 ? "" : `${occurenceTillNow}`
archive.entry(filestream, { name: `${fileName}${suffix}`} )
}
}