使用SaveFileDialog将目录导出为zip
我正在使用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设置目标文件的位置。
有谁知道我怎么能让用户设置目的地在哪里使用node-webkit中的SaveFileDialog导出压缩文件?
根据node-webkit的wiki,您可以通过模拟点击一个专门configuration的htmlinput字段来以编程方式打开一个对话框 。
所以,例如,你会插入
<input type="file" id="fileDialog" nwsaveas /> <!-- or specify a default filename: --> <input type="file" id="fileDialog" nwsaveas="myfile.txt" />
并使用这样的东西来有select地编程触发对话框,并获得input的path:
function chooseFile(name) { var chooser = document.querySelector(name); chooser.addEventListener("change", function(evt) { console.log(this.value); }, false); chooser.click(); } chooseFile('#fileDialog');