How to use the asar.extractFile function in asar

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 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 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 doyensec / electronegativity / src / loader / loader_asar.js View on Github external
for (const file of archived_files) {
      if(file.startsWith(`${path.sep}node_modules`)) continue;

      const f = file.startsWith(path.sep) ? file.substr(1) : file;
      switch (extension(f)) {
        case 'json':
          if (f.toLowerCase().indexOf('package.json') < 0)
            continue;
        case 'js':
        case 'jsx':
        case 'ts':
        case 'tsx':
        case 'htm':
        case 'html':
          logger.debug(`Extracting file: ${f}`);
          const buffer = asar.extractFile(archive, f);
          this.load_buffer(buffer, f);
          break;
        default:
          break;
      }
    }

    logger.debug(`Loaded ${this.loaded.size} files`);

    return this.loaded;
  }
}
github electron / windows-installer / src / index.ts View on Github external
loadingGif = loadingGif ? path.resolve(loadingGif) : defaultLoadingGif;

  let { certificateFile, certificatePassword, remoteReleases, signWithParams, remoteToken } = options;

  const metadata: Metadata = {
    description: '',
    iconUrl: 'https://raw.githubusercontent.com/atom/electron/master/atom/browser/resources/win/atom.ico'
  };

  if (options.usePackageJson !== false) {
    const appResources = path.join(appDirectory, 'resources');
    const asarFile = path.join(appResources, 'app.asar');
    let appMetadata;

    if (await fs.pathExists(asarFile)) {
      appMetadata = JSON.parse(asar.extractFile(asarFile, 'package.json'));
    } else {
      appMetadata = await fs.readJson(path.join(appResources, 'app', 'package.json'));
    }

    Object.assign(metadata, {
      exe: `${appMetadata.name}.exe`,
      title: appMetadata.productName || appMetadata.name
    }, appMetadata);
  }

  Object.assign(metadata, options);

  if (!metadata.authors) {
    if (typeof (metadata.author) === 'string') {
      metadata.authors = metadata.author;
    } else {
github CKarper / asar-fs / src / monkey.js View on Github external
function readPackage(pkgFile) {
  if (Object.prototype.hasOwnProperty.call(packageMainCache, pkgFile)) {
    return packageMainCache[pkgFile];
  }

  const jsonPath = pkgFile;
  const json = asar.extractFile(_archFs.src, pkgFile);

  if (json === undefined) {
    return false;
  }

  let pkg;
  try {
    packageMainCache[pkgFile] = JSON.parse(json).main;
    pkg = packageMainCache[pkgFile];
  }
  catch (err) {
    err.path = jsonPath;
    err.message = `Error parsing ${jsonPath}: ${err.message}`;
    throw err;
  }
  return pkg;

asar

Creating Electron app packages

MIT
Latest version published 2 years ago

Package Health Score

58 / 100
Full package analysis

Similar packages