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 to zip single file #667

Open
RadoslavMarinov opened this issue Aug 10, 2023 · 1 comment
Open

How to zip single file #667

RadoslavMarinov opened this issue Aug 10, 2023 · 1 comment

Comments

@RadoslavMarinov
Copy link

Im trying to zip a single file using archiver and I succeed but resulting zip file contains directory when unzipped and I want just the file.

Here is a sample code:

export async function zipFile(srcFilePath: string, zipFilePath: string) {
  const output = fs.createWriteStream(zipFilePath);
  const archive = archiver('zip',{
    zlib:{
      level: 9
    }
  })

  return new Promise((resolve,reject)=>{
    output.on('close', function() {
      console.log('ARCHIVE FINISHED.');
      resolve(zipFilePath)
    });

    archive.on('error', function(err) {
      reject(err)
    });

    archive.pipe(output);
    archive.file(srcFilePath, {name:path.basename(srcFilePath)})

    archive.finalize();

  })
}

  const zippedFile = await zipFile(
    "/home/rikotech/code/scalewest/repos/hype-nielsen-report/csv/csv.csv",
    "/home/rikotech/code/scalewest/repos/hype-nielsen-report/csv/zipped.zip"
  ); 

The result is zipped.zip and when I unzip it I see a folder named zipped and then iside the folder I have the unzipped file csv.csv.

I want when I unzip the zip file to get a file (the csv file) not a folder and in it the file.

@Alexsey
Copy link

Alexsey commented Mar 19, 2024

I've faced the same issue. This is not because of archiver but because of the tool being used to unzip. In my case, it was the default MacOS Archive Utility.app - it is used when you double-click on an archive

On MacOS, to check the content of the archive, do unzip -l path/to/your/archive.zip or unzip path/to/your/archive.zip to unzip - you will see that there is no folder

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