1

I'm using archiver to export a directory as a zip file in nodejs/node-webkit.

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()

However I can't find anything on how to have the user set the destination on where the zip file should be exported using a traditional SaveFileDialog.

Does anyone know how I can have the user set the destination on where to export the zip file using a SaveFileDialog in node-webkit?

Michael Schwartz
  • 8,153
  • 14
  • 81
  • 144

1 Answers1

2

According to node-webkit's wiki, you can open a dialog programmatically by simulating a click on a specially configured html input field.

So for example you would insert

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

and use something like this to optionally programmatically trigger the dialog and get the entered path:

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

  chooser.click();  
}
chooseFile('#fileDialog');
mscdex
  • 104,356
  • 15
  • 192
  • 153