【问题标题】:Export directory as zip with a SaveFileDialog使用 SaveFileDialog 将目录导出为 zip
【发布时间】:2016-07-12 15:40:24
【问题描述】:

我正在使用archiver 将目录导出为 nodejs/node-webkit 中的 zip 文件。

var file_system = require("fs")
var archiver = require("archiver")

var output = file_system.createWriteStream("files.zip")
var archive = archiver("zip")

output.on("close", function() {
  console.log(archive.pointer() + " total bytes")
  console.log("archiver has been finalized and the output file descriptor has closed.")
})

archive.on("error", function(err) {
  throw err
})

archive.pipe(output)
archive.bulk([
  { expand: true, cwd: "./content/project/", src: ["**"], dest: "./content/project/"}
])
archive.finalize()

但是,我找不到任何关于如何让用户使用传统的 SaveFileDialog 将 zip 文件导出到的目标位置。

有谁知道我如何让用户使用 node-webkit 中的 SaveFileDialog 设置导出 zip 文件的目的地?

【问题讨论】:

    标签: node.js save node-webkit nw.js iojs


    【解决方案1】:

    根据node-webkit的wiki,你可以通过模拟点击specially configured html input fieldopen a dialog programmatically

    所以例如你会插入

    <input type="file" id="fileDialog" nwsaveas />
    <!-- or specify a default filename: -->
    <input type="file" id="fileDialog" nwsaveas="myfile.txt" />
    

    并使用类似的方法选择性地以编程方式触发对话框并获取输入的路径:

    function chooseFile(name) {
      var chooser = document.querySelector(name);
      chooser.addEventListener("change", function(evt) {
        console.log(this.value);
      }, false);
    
      chooser.click();  
    }
    chooseFile('#fileDialog');
    

    【讨论】:

      猜你喜欢
      • 2011-01-08
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      相关资源
      最近更新 更多