Electron version: 1.2 Operating system: Windows
Cannot able to access the files inside asar archive using readFileSync:
var fs = require('fs');
var SQL = require('sql.js');
var filebuffer = fs.readFileSync('asar:'+ __dirname + './app/data/sample.db');
I've also tried using
trial 1 : readFileSync('D:/Sample-App/app.asar/app/data/sample.db');
trial 2 : readFileSync('./app/data/sample.db');
trial 3 : process.noAsar= true;
readFileSync('./app/data/sample.db');
None of the trials worked out. If I try without using app.asar, I was able to access the db file. So Please help me resolve this issue.
I'm assuming you mean that once you package your app to an asar, your file paths don't work.
fs.readFileSync('asar:'+ __dirname + './app/data/sample.db')
This is close. You don't need "asar:" and you should use the path module to make your life easier.
Try constructing a path dynamically using path
. Also your main entry point JS is probably already running in the app folder. Try something like this:
path.join(__dirname, '/data/sample.db');
This will create a valid, absolute path for each operating system (paths in Windows use \ whereas OSX and Linux uses /). Remember __dirname
is whatever your current directory is, so everything after that has to be relative to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With