Skip to content
/ phar.js Public

Utilities for working with Phar archives in JavaScipt

License

Notifications You must be signed in to change notification settings

ScerIO/phar.js

Repository files navigation

Phar.js

Utilities for working with PHAR archives in JavaScipt

NPM Version NPM Downloads

Supported modules types: UMD (CommonJS + AMD), SystemJS, es2015

Docs located here

Install

  • NPM
npm i -S phar
  • Bower
bower i -S phar

Usage

  • Node.js (CommonJS)
const PHAR = require('phar')
// PHAR.Archive
// PHAR.File
  • Browser (RequireJS (UMD))
<script src="bower_components/phar/lib/webpack/phar"></script>
<script>
  require(['phar'], (PHAR) => {
    // PHAR.Archive
    // PHAR.File
  })
</script>
  • Loading Phar archive from contents
// Phar contents as <string> or <Uint8Array>
const phar = new PHAR.Archive();
phar.loadPharData(phar_contents);
  • Creating new Phar archive
const phar = new PHAR.Archive();
phar.setStub('<?php echo "Works!" . PHP_EOL; __HALT_COMPILER();');
phar.setSignatureType(PHAR.Signature.SHA256);
  • Adding file to Phar archive
// Phar object
const file = new PHAR.File("myName.txt", "some_contents");
phar.addFile(file);
  • Saving Phar archive to contents
// Phar object
const pharContents = phar.savePharData();
  • Converting to Zip
// Phar object
PHAR.ZipConverter.toZip(phar)
  .then((data) => {
    return data.generateAsync({
      type: 'uint8array'
    })
  })
  .then((zip) => { /* ... */ })
  • Converting from zip
PHAR.ZipConverter.toPhar(fs.readFileSync('test.zip'))
  .then((phar) => { /* ... */ })

...and more! Just look at the source.