Phar.js
Utilities for working with PHAR archives in JavaScipt
Supported modules types: UMD (CommonJS + AMD), SystemJS, es2015
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 objectconst file = new PHAR.File("myName.txt", "some_contents");phar.addFile(file);
- Saving Phar archive to contents
// Phar objectconst pharContents = phar.savePharData();
- Converting to Zip
// Phar objectPHAR.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.