zoukankan      html  css  js  c++  java
  • node,js download实现下载文件并解压后删除

     var express = require('express');
      var router = express.Router();
      const fs = require('fs');
      var unzip = require("unzip");
      const download = require('download');
    (async () => {
        // await download('http://172.20.33.25:8088/upload/download.action?fileName=345.zip&md5=bc09d226db664c8b362743608f6f74ca&type=zip&size=153&fileId=1264&time=1599548153286&filename=bc09d226db664c8b362743608f6f74ca.zip ', './');
    
        fs.writeFileSync('./123.zip', await download('http://172.20.33.25:8088/upload/download.action?fileName=345.zip&md5=bc09d226db664c8b362743608f6f74ca&type=zip&size=153&fileId=1264&time=1599548153286&filename=bc09d226db664c8b362743608f6f74ca.zip'));
    
        // download('http://172.20.33.25:8088/upload/download.action?fileName=345.zip&md5=bc09d226db664c8b362743608f6f74ca&type=zip&size=153&fileId=1264&time=1599548153286&filename=bc09d226db664c8b362743608f6f74ca.zip ').pipe(fs.createWriteStream('./123.zip'));
    
        // await Promise.all([
        //     'http://172.20.33.25:8088/upload/download.action?fileName=345.zip&md5=bc09d226db664c8b362743608f6f74ca&type=zip&size=153&fileId=1264&time=1599548153286&filename=bc09d226db664c8b362743608f6f74ca.zip ',
        // ].map(url => download(url, './')));
    
        var extract = unzip.Extract({ path: './' });
        fs.createReadStream('./123.zip').pipe(extract);
        extract.on('close', function () {
            console.log("解压完成!!");
            //删除
            fs.unlinkSync('./123.zip');
        });
        extract.on('error', function (err) {
            console.log(err);
        });
    
      })();
  • 相关阅读:
    angluar 判断后跳转加参数
    angular 返回上一页
    angular 组件跳转组件 并传参数
    angluar 表单提交时候报错
    angular 中获取select选中的值
    javascript
    将数据渲染到页面的方式:模版
    将数据渲染到页面的几种方式
    跨域
    ajax
  • 原文地址:https://www.cnblogs.com/150536FBB/p/13638534.html
Copyright © 2011-2022 走看看