Have ideas to improve npm?Join in the discussion! »

    wbn
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.5 • Public • Published

    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 wbn

    Usage

    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))
      .setManifestURL('https://example.com/manifest.json')
      .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));

    CLI

    This package also includes wbn command which lets you build a web bundle from a local directory. For example, if you have all the necessary files for https://example.com/ in static/ directory, run the following command:

    $ wbn --dir static \
          --baseURL https://example.com/ \
          --output out.wbn

    Run wbn --help for full options.

    Note: currently this CLI only covers a subset of the functionality offered by gen-bundle Go tool.

    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.

    Install

    npm i wbn

    DownloadsWeekly Downloads

    107

    Version

    0.0.5

    License

    W3C-20150513

    Unpacked Size

    20 kB

    Total Files

    11

    Last publish

    Collaborators

    • avatar
    • avatar