orangewise / s3-zip

Download selected files from an Amazon S3 bucket as a zip file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot include same file multiple times with a different name

DavisBrown723 opened this issue · comments

Take the following scenario as an example

// files to grab from s3
filesS3= [
  "x/y/z/file_1.png",
  "x/y/z/file_1.png",
];

// the structure of the zip file
filesZip = [
  "folder1/file_1_v1.png",
  "folder1/folder2/file_1_v2.png",
];

Here, I would expect the zipped folder to contain two instances of the same file, each with a different name (file_1_v1.png and file_1_v2.png). Instead, there are two instances of the same file, but they both get recongized as being filesS3[0] which will result in them both having the name corresponding to filesZip[0].

Is this something you would consider changing, even if it needs to be specified as an option when calling s3Zip.archive(...) to retain backwards-compatibility? If so, I can submit a PR. It seems the only core change that needs to be made is adding filesS3[i] = ""; after line 58. That way each subsequent access of the s3key will access the next name found in filesZip.

Thanks for the response @orangewise, that is the current method I am using - which leads to the issue seen above.
As the files retrieved from s3 are streamed in, the index of filesZip that will be used for the filename in the zipped folder is calculated by looking for the S3 key in filesS3. When the same filename is used twice, the index corresponding to the first occurrence of the key in filesS3 is used. Thus, you end up with a situation where both of the files being zipped have the same name.

If you set filesS3[i] = ""; after finding the name of each streamed file, then any following streamed files that refer to the same S3 key will use the proper index from filesZip.

Hopefully that makes sense.

Ok ok, understand. Would you be able to create a PR including a unit test? Will merge it in asap.

Sure, I'll get started on it.