Giter Club home page Giter Club logo

browser-asar's Introduction

browser-asar

Handle asar file in browser. (Readonly)

AJAX demo: https://toyobayashi.github.io/browser-asar/

File input demo: https://toyobayashi.github.io/browser-asar/file.html

Running demo: https://toyobayashi.github.io/browser-asar/test.html

Support IE 10+ (require Uint8Array)

Usage

You can find examples in docs/ and test/.

<!-- Get it from package.json "main" field -->
<script src="asar.js"></script>
var xhr = new XMLHttpRequest();
xhr.onload = function () {
  var buf = new Uint8Array(xhr.response);
  var fs;
  try {
    fs = new asar.Filesystem(buf);
  } catch (err) {
    throw new Error('Invalid asar file: ' + err.message);
  }

  // Then you can do something like Node.js `fs` module.
  // Note the asar package is readonly.
  // Available API list can be found below.

  // fs.readFileSync(...)
  // fs.existsSync(...)
  // fs.statSync(...).isDirectory()
  // ...

  // Run as a Node.js project folder
  var ms = new asar.Modulesystem(fs);
  ms.run();
};
xhr.open('GET', './test.asar', true);
xhr.responseType = 'arraybuffer';
xhr.send();

Available builtin modules in asar package:

  • path - posix part only

  • fs

  • module

API

declare class Stat {
  constructor(info: any);
  readonly size: number;
  isUnpacked(): boolean;
  isDirectory(): boolean;
  isFile(): boolean;
  isSymbolicLink(): boolean;
}

declare class Module {
  constructor(id: string, parent: Module | null);
  id: string;
  filename: string;
  path: string;
  parent: Module | null;
  loaded: boolean;
  exports: any;
  children: Module[];
  paths: string[];
  require(mod: string): any;
}

export declare class Filesystem {
  constructor(buffer: Uint8Array);
  readonly buffer: Uint8Array;
  readonly header: { files: { [item: string]: any } };
  readonly headerSize: number;
  listFiles(options?: { isPack?: boolean }): string[];
  readFileSync(p: string): Uint8Array;
  readFileSync(p: string, toUtf8: true): string;
  readdirSync(p: string): string[];
  existsSync(p: string): boolean;
  statSync(p: string): Stat;
  lstatSync(p: string): Stat;
}

export declare class Modulesystem {
  constructor(fs: Filesystem | Uint8Array);
  static run(fs: Filesystem, entry?: string): any;
  static inject(moduleName: string, m: any): void;
  static require(moduleName: string): any;
  static extend(ext: string, compilerFactory: (require: (moduleName: string) => any) => (module: Module, filename: string) => void): void;
  run(entry?: string): any;
  inject(moduleName: string, m: any): void;
  require(moduleName: string): any;
  extend(ext: string, compilerFactory: (this: Modulesystem, require: (this: Modulesystem, moduleName: string) => any) => (module: Module, filename: string) => void): void;
}

export as namespace asar;

browser-asar's People

Contributors

toyobayashi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.