Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "pnkg", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "PNG bundler", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,2 +13,4 @@ # PNKG [![Build Status](https://api.travis-ci.com/swashvirus/pnkg.svg?branch=main)](https://travis-ci.com/swashvirus/pnkg) | ||
```javascript | ||
const fs = require("fs") | ||
const {PNG} = require("pngjs") | ||
const {pack, unpack} = require("pnkg") | ||
@@ -21,3 +23,9 @@ ``` | ||
``` | ||
``` | ||
Usage: pnkg [options] [command] | ||
Commands: | ||
pack [options] <file> | ||
unpack <file> | ||
help [command] display help for command | ||
``` | ||
## Documentation | ||
@@ -27,4 +35,31 @@ _(Coming soon)_ | ||
## Examples | ||
_(Coming soon)_ | ||
### Packing files | ||
```javascript | ||
fs.createReadStream("<image_path>") | ||
.pipe(new PNG()) | ||
.on("parsed", function() { | ||
// read file payload | ||
fs.readFile("<data_file_path>", function (error, file_data) { | ||
if (error) { | ||
throw new Error(error) | ||
} | ||
// override image data with pnkged data. | ||
this.data = pack(new Uint8Array(this.data), new Uint8Array(file_data)) | ||
this.pack() | ||
.pipe(fs.createWriteStream("<destination_path>")) | ||
}) | ||
}) | ||
``` | ||
### Unpacking data | ||
```javascript | ||
fs.createReadStream("<destination_path>") | ||
.pipe(new PNG()) | ||
.on("parsed", function() { | ||
fs.writeFile("<data_file_path>"), unpack(new Uint8Array(this.data)), function(error) { | ||
if (error) { | ||
throw new Error(error) | ||
} | ||
} | ||
}) | ||
``` | ||
## Contributing | ||
@@ -31,0 +66,0 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). |
37221
71