SHARE
TWEET

Untitled

a guest Jun 18th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function canWrite(path, callback) {
  2.     fs.access(path, fs.W_OK, function (err) {
  3.         callback(null, !err);
  4.     });
  5. }
  6.  
  7. function downloadFile(url, target, target_name) {
  8.     canWrite(target, function (err, isWritable) {
  9.         if (isWritable){
  10.             electronDl.download(
  11.                 BrowserWindow.getFocusedWindow(),
  12.                 url,
  13.                 {
  14.                     directory: target,
  15.                     filename: target_name
  16.                 }
  17.             )
  18.             console.log("Downloaded from: " + url + " to: " + target);
  19.             return true;
  20.         } else {
  21.             console.log("No permission to write to target");
  22.             return false;
  23.         }
  24.     });
  25. }
  26. downloadFile(REMOTEURL, app.getPath('userData'), 'sessionfile.json');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top