Package Exports
- wbn
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wbn) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Web Bundles
This is a Node.js module for serializing and parsing the application/webbundle
format defined in the Web
Bundles
draft spec.
Currently this library doesn't support origin-signed bundles, but bundles generated by this library can be signed with the sign-bundle Go tool.
Installation
Using npm:
npm install wbnUsage
Please be aware that the API is not yet stable and is subject to change any time.
Creating a Bundle:
const wbn = require('wbn');
const fs = require("fs");
const primaryURL = 'https://example.com/';
const builder = new wbn.BundleBuilder(primaryURL);
builder.setManifestURL('https://example.com/manifest.json');
builder.addExchange(
primaryURL, // URL
200, // response code
{'Content-Type': 'text/html'}, // response headers
'<html>Hello, Web Bundle!</html>'); // response body (string or Uint8Array)
// Have as many builder.addExchange() for resource URLs as needed for the package.
fs.writeFileSync('out.wbn', builder.createBundle());Reading a Bundle:
const wbn = require('wbn');
const fs = require("fs");
const buf = fs.readFileSync('out.wbn');
const bundle = new wbn.Bundle(buf);
const exchanges = [];
for (const url of bundle.urls) {
const resp = bundle.getResponse(url);
exchanges.push({
url,
status: resp.status,
headers: resp.headers,
body: resp.body.toString('utf-8')
});
}
console.log(JSON.stringify({
version: bundle.version, // format version
primaryURL: bundle.primaryURL,
manifestURL: bundle.manifestURL,
exchanges
}, null, 2));Using Bundles
Generated bundles can be opened with web browsers supporting web bundles.
Chrome (79+) experimentally supports Web Bundles with some limitations. See this document for more details.