Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I deal with different files with the same name and zip them? #59

Open
PseudoCowboy opened this issue Sep 10, 2020 · 1 comment

Comments

@PseudoCowboy
Copy link

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.

@97amarnathk
Copy link

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}`} )
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants