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

Fix zipping large number of files issue #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dany611
Copy link

@dany611 dany611 commented Nov 8, 2019

No description provided.

@dany611
Copy link
Author

dany611 commented Nov 8, 2019

This issue #26 has been fixed. @DanielHindi @andrewsomething @ggoforth @relly @ygalbel

@trongpham-itr
Copy link

trongpham-itr commented Dec 31, 2019

I found some bug, I fixed it, you can check again. Thanks @dany611

    this.getFiles(params, async (err, clearedFiles) => {
      if (err) console.error(err);
      else {
        const { files } = clearedFiles;
        let filesList = [];
        const batchSize = 10;

        let filesValid = [];

        while (((filesList = files.splice(0, batchSize)).length) !== 0) {
          const promises = _.map(filesList, async f => new Promise((resolve, reject) => {
            this.s3bucket.getObject({ Bucket: this.awsConfig.bucket, Key: f.Key }, (error, data) => {
              if (error) {
                console.log(error);
                reject(error);
              } else {
                const name = this.calculateFileName(f);
                if (name === '') {
                  resolve(f);
                } else {
                  console.log('zipping ', name, '...');
                  zip.append(data.Body, { name });
                  resolve(f);
                }
              }
            });
          }));

          const result = await Promise.all(promises);
          filesValid = _.concat(filesValid, result);
        }
        zip.manifest = filesValid;
        zip.on('finish', () => {
          callback(err, {
            zip,
            zippedFiles: filesValid,
            totalFilesScanned: clearedFiles.totalFilesScanned,
            lastScannedFile: clearedFiles.lastScannedFile,
          });
        });
        zip.finalize();
      }
    });

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

Successfully merging this pull request may close these issues.

2 participants