- Tool to pack binary files into a PNG image.
- Users can load a
bundle.wpfile and extract its data indexed by the original file's path.- A file in the folder
root/img/logo.pngcan be accessed bybundle.read("img/logo.png") == Uint8Array - Helper methods allow users to read the desired data format.
var d = bundle.readJSON("data/file.json") == objectvar s = bundle.readText("data/file.txt") == stringvar img = bundle.readImg("img/logo.jpg") == ImageElement
- A file in the folder
This PNG contains the following files:
- xml.dae
- data.json
- portrait.png
- Significantly reduce the number of HTTP requests allowing fast page loads
- Text data can be at least 40% compressed
- Browsers decompression routines are native and fast
- Games can greatly benefit of the compression and data packing
- No need to create and manage your own pack data type
- Install the
wbtool with$ npm install web-bundle, or find it intool/wb.js - In the command line, run
$ wb encode -o my-bundle.wb foo.json bar.png - After running,
foo.jsonandbar.pngwill be stored inmy-bundle.png - Use
--outputor-oto choose the output location for the bundle - Use
--addorato add files to an existing bundle instead of creating a new one - See
wb --helpfor more
- Install web-bundle with
npm install --save web-bundle
var wb = require('web-bundle');
var bundle = new wb.Bundle();
bundle.addFile('foo.png', function(err) {
// some/dir/foo.png has been added to the bundle
bundle.write('bundle.wb', function(err) {
// Bundle written
});
});- Add the scripts
deploy/js/wb.jsordeploy/js/wb.min.jsto your page.
var b = new Bundle();
b.load("data/output.wb",function(bundle,progress)
{
if(progress >= 1.0)
{
if(bundle != null)
{
bundle.read[Text|JSON|Img|...]("data-id");
}
}
},[password]);- Make sure
<script src='js/wb.js'/>exists in your page. - Make sure the
web-bundlelibrary is installed and linked in your project.- Use
haxelibto install the library. haxelib git web-bundle https://github.com/haxorplatform/web-bundle.git 1.0
- Use
import js.Bundle;
var b : Bundle = new Bundle();
b.load("data/output.wb",function(bundle:Bundle,progress:Float)
{
if(progress >= 1.0)
{
if(bundle != null)
{
bundle.read[Text|JSON|Img|...]("data-id");
}
}
},[password]);- Install with
$ npm install --save web-bundle
var wb = require('web-bundle');
var bundle = new wb.Bundle();
bundle.load('my-bundle.wb', function(err) {
// Bundle loaded
bundle.read('foo.json') // -> Buffer
bundle.readString('foo.json') // -> string
bundle.readJSON('foo.json') // -> Object
});- Install the
wbtool with$ npm install web-bundle, or find it intool/wb.js - To see the contents of a bundle, run
$ wb ls my-bundle.wb - To extract all files, use
$ wb decode my-bundle.wb - Specify an output location with
--outputor-o:$ wb decode my-bundle.wb --output some/dir - Extract a single file with
--extractor-e:$ wb decode my-bundle.wb --extract foo.png - See
$ wb --helpfor more
