DanielHindi / aws-s3-zipper

takes an amazon s3 bucket folder and zips it for streaming or serializes to a file
119 stars 74 forks source link

RAM did not release if downloading was cancelled and files are corrupted after complete download using streamZipDataTo #57

Open RizwanAhmad-dev opened 11 months ago

RizwanAhmad-dev commented 11 months ago

I'm using latest version of AWS-s3-zipper to download complete s3 folder if its get downloaded files were corrupted, and if user cancel the downloading before completion, if hold RAM and did not release it.

steps - create simple NodeJs Express server with download api - hit the /download/{gameId} where game Id is the folder of s3 bucket it will start the downloading

here is the code - app.get("/download/:gameId", async (req, res, next) => { try { const { gameId } = req.params; const params = { Bucket: config.bucket.name, Prefix:cloudpokernight/${gameId}`, }; const command = new ListObjectsV2Command(params); const data = await s3.send(command);

if (!data || !data.Contents || data.Contents.length === 0) {
  return res.status(404).json({ code: 404, error: 'Folder not found in S3' });
}
res.set("content-type", "application/zip");
res.set("Content-Disposition", `attachment; filename=${gameId}.zip`);
zipper.streamZipDataTo(
  {
    pipe: res,
    folderName: params.Prefix,
    startKey: null,
    recursive: true,
  },
  function (err, result) {
    if (err) console.error(err);
    else {
      console.log(result);
    }
  },
);

} catch (err) { next(err); } });`