Utilities for working with PHAR archives in JavaScipt
Supported modules types: UMD (CommonJS + AMD), SystemJS, es2015
- NPM
npm i -S phar
- Bower
bower i -S phar
- 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.