Simplest way to download and unzip files in Node.js cross-platform?

前端 未结 11 1580
一个人的身影
一个人的身影 2020-11-30 23:44

Just looking for a simple solution to downloading and unzipping .zip or .tar.gz files in Node.js on any operating system.

Not sure if this

11条回答
  •  时光说笑
    2020-11-30 23:58

    Checkout gunzip-file

    import gunzip from 'gunzip-file';
    
    const unzipAll = async () => {
      try {
        const compFiles = fs.readdirSync('tmp')
        await Promise.all(compFiles.map( async file => {
          if(file.endsWith(".gz")){
            gunzip(`tmp/${file}`, `tmp/${file.slice(0, -3)}`)
          }
        }));
      }
      catch(err) {
        console.log(err)
      }
    }
    

提交回复
热议问题