How to use asar - 10 common examples

To help you get started, we’ve selected a few asar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electron / electron / script / gn-asar.js View on Github external
// Copy all files to a tmp dir to avoid including scrap files in the ASAR
  for (const file of files) {
    const newLocation = path.resolve(tmpPath, path.relative(base[0], file))
    fs.mkdirsSync(path.dirname(newLocation))
    fs.writeFileSync(newLocation, fs.readFileSync(file))
  }
} catch (err) {
  console.error('Unexpected error while generating ASAR', err)
  fs.remove(tmpPath)
    .then(() => process.exit(1))
    .catch(() => process.exit(1))
  return
}

// Create the ASAR archive
asar.createPackageWithOptions(tmpPath, out[0], {})
  .catch(err => {
    const exit = () => {
      console.error('Unexpected error while generating ASAR', err)
      process.exit(1)
    }
    fs.remove(tmpPath).then(exit).catch(exit)
  }).then(() => fs.remove(tmpPath))
github nils-kt / asar-package-obfuscator / index.js View on Github external
var fs = require('fs');
var path = require('path');
var recursive = require('recursive-readdir');
var rimraf = require('rimraf');
var asar = require('asar');
var javaScriptObfuscator = require('javascript-obfuscator');

// Set your resources folder
var resourcesFolder = 'C:\\example-electron\\dist\\win-unpacked\\resources';

console.log('\n\nasar package javascript obfuscator\n\n');

console.log('Unpacking archive');
asar.extractAll(resourcesFolder + '\\app.asar', resourcesFolder + '\\src');

console.log('Deleting app.asar');
fs.unlinkSync(resourcesFolder + '\\app.asar');

// Enter the directories to be ignored
recursive(resourcesFolder + '\\src', ['node_modules', 'app'], function (err, files) {
    files.forEach(file => {
        if (path.extname(file) === '.js') {
            let contents = fs.readFileSync(file, 'utf8');
            console.log('Protecting ' + file);

            // Change the settings here  -  https://github.com/javascript-obfuscator/javascript-obfuscator
            let ret = javaScriptObfuscator.obfuscate(contents, {
                compact: true
                , controlFlowFlattening: false
                , controlFlowFlatteningThreshold: 0.75
github CKarper / asar-fs / src / monkey.js View on Github external
// If it's not archive prefixed, strip a single parent directory...
  if (/^\.\.\//.test(relFile)) {
    relFile = relFile.substr(3);
  }
  // If it's still got a parent directory, or starts with /, it's not in our archive...
  if (!/^\.\.\/|^\//.test(relFile)) {
    let f;
    try {
      const node = _archFs.searchNodeFromDirectory(relFile);
      if (node && node.size) {
        let encoding;
        if (options && typeof options === 'string') {
          encoding = options;
        }

        f = asar.extractFile(_archFs.src, relFile);
        if (encoding) { f = f.toString(encoding); }
      }
    }
    catch (err) {}
    return f;
  }
  return undefined;
}
github wojtkowiak / meteor-desktop / lib / meteorApp.js View on Github external
return new Promise((resolve, reject) =>
            asar.createPackage(
                this.$.env.paths.electronApp.meteorApp,
                path.join(this.$.env.paths.electronApp.root, 'meteor.asar'),
                () => {
                    // On Windows some files might still be blocked. Giving a tick for them to be
                    // ready for deletion.
                    setImmediate(() => {
                        this.log.verbose('clearing meteor app after packing');
                        this.$.utils
                            .rmWithRetries('-rf', this.$.env.paths.electronApp.meteorApp)
                            .then(() => {
                                resolve();
                            })
                            .catch((e) => {
                                reject(e);
                            });
                    });
github proin / saturn / controller / express / api / script / import.js View on Github external
router.get("/", function (req, res) {
    // only allow for user
    if (req.user.check() !== 'GRANTALL') return;

    let {name} = req.query;

    if (!name) return res.send({err: new Error('not defined name')});

    const PRJ_PATH = path.resolve(req.DIR.WORKSPACE_PATH, `${name}.satbook`);
    const DOWNLOAD_PATH = path.resolve(req.DIR.TMPD, `download`, `${name}.satbook`);

    if (!fs.existsSync(PRJ_PATH)) return res.send({err: new Error('no work')});

    asar.createPackage(PRJ_PATH, DOWNLOAD_PATH, function () {
        res.download(DOWNLOAD_PATH);
    });
});
github figma-plus / installer / renderer.js View on Github external
var code = fs.readFileSync(`${rootFolder}/code.js`, 'utf8');

  if (fs.existsSync(output)) removeSync(output);
  if (fs.existsSync(input)) removeSync(input);

  // replace injected packs with backups
  if (fs.existsSync(backupAsar)) {
    if (fs.existsSync(originalAsar)) removeSync(originalAsar);
    removeSync(originalAsar);
    originalFs.copyFileSync(backupAsar, originalAsar);
    removeSync(backupAsar);
  }

  // bring figma files
  asar.extractAll(originalAsar, input);


  // inject code

  const useLocalPluginsManager = store.get('useLocalPluginsManager', false);

  if (useLocalPluginsManager) {
    const localPluginsManagerUrl = store.get('localPluginsManagerUrl', "https://jachui.github.io/figma-plugin-manager");
    code = code.replace(/SERVER_URL/g, localPluginsManagerUrl.replace(/\/$/, ""));
  }
  else {
    code = code.replace(/SERVER_URL/g, "https://jachui.github.io/figma-plugin-manager");
  }

  const devMode = store.get('devMode', false);
github sindrets / atom-title-bar-replacer / lib / window-frame-remover.js View on Github external
setTimeout(function () {
                    if (exists["app.asar.unpacked"])
                        _this.copyFolderRecursiveSync(rootPath + "app.asar.unpacked", rootPath + "app.asar.bak.unpacked");
                    _this.extractAsarAsync(rootPath + "app.asar.bak", rootPath + "_app-extract", function () {
                        _this.removeFrame(6, exists);
                    });
                    // Update info text on extraction progress until complete.
                    var total = asar.listPackage(rootPath + "app.asar.bak").length;
                    var progress;
                    var intervalId = setInterval(function () {
                        progress = _this.numFilesSync(rootPath + "_app-extract");
                        if (progress >= total)
                            clearInterval(intervalId);
                        modalDiv.setInfo("Extracted " + progress + " of " + total + ".");
                    }, 500);
                }, 50);
                break;
github electron-userland / electron-forge / test / slow / api_spec_slow.js View on Github external
it('should have deleted the forge config from the packaged app', async () => {
        const cleanPackageJSON = JSON.parse(asar.extractFile(
          path.resolve(dir, 'out', `Test App-${process.platform}-${process.arch}`, resourcesPath, 'app.asar'),
          'package.json'
        ));
        expect(cleanPackageJSON).to.not.have.nested.property('config.forge');
      });
github DevExpress / testcafe-hammerhead / src / utils / asar.ts View on Github external
extractFileToReadStream (archive: string, fileName: string): Readable {
        const extractedFile = asar.extractFile(archive, fileName);

        return toReadableStream(extractedFile);
    }
github electron / electron / spec / coverage / instrument.js View on Github external
var libPath = path.join(__dirname, '..', '..', 'lib')

rimraf.sync(path.join(outputPath, 'lib'))

glob.sync('**/*.js', {cwd: libPath}).forEach(function (relativePath) {
  var rawPath = path.join(libPath, relativePath)
  var raw = fs.readFileSync(rawPath, 'utf8')

  var generatedPath = path.join(outputPath, 'lib', relativePath)
  var generated = instrumenter.instrumentSync(raw, rawPath)
  mkdirp.sync(path.dirname(generatedPath))
  fs.writeFileSync(generatedPath, generated)
})

var asarPath = path.join(outputPath, 'electron.asar')
asar.createPackageWithOptions(path.join(outputPath, 'lib'), asarPath, {}, function (error) {
  if (error) {
    console.error(error.stack || error)
    process.exit(1)
  }
})

asar

Creating Electron app packages

MIT
Latest version published 2 years ago

Package Health Score

58 / 100
Full package analysis