node package manager



streaming html templates

like hyperstream, but faster. it does not support all hyperstream features.

currently unsupported:

  • inserting text; only html is supported
  • prepending or appending to attributes

npm travis standard


npm install hstream


var hyperstream = require('hstream')
  'div > .x[attr="value"]': fs.createReadStream('./xyz.html')



Create a through stream that applies updates. updates is an object with CSS selectors for keys. Values can be different types depending on what sort of update you want to do.

Selectors support the most common CSS features, like matching tag names, classes, IDs, attributes. Pseudo selectors are not supported, but PRs are welcome.

Pass a stream or string to replace the matching element's contents with some HTML. Pass an object to set attributes on the matching element or do some special operations. When passing an object, you can use keys prefixed with _ for the following special operations:

  • _html - Replace the matching element's contents with some HTML
  • _prependHtml - Prepend some HTML to the matching element
  • _appendHtml - Append some HTML to the matching element
  • _replaceHtml - Replace the entire element with some HTML

All properties accept streams and strings.

  '#a': someReadableStream(), // replace content with a stream
  '#b': 'a string value', // replace content with a string
  // prepend and append some html
  '#c': { _prependHtml: 'here comes the <b>content</b>: ', _appendHtml: ' …that\'s all folks!' },
  // replace content with a stream and set an attribute `attr="value"`
  '#d': { _html: someReadableStream(), 'attr': 'value' },
  // set an attribute `data-whatever` to a streamed value
  '#e': { 'data-whatever': someReadableStream() }


Run npm run bench.

NANOBENCH version 2
> node bench/hyperstream.js

# hyperstream single
ok ~5.38 s (5 s + 381237046 ns)

# hyperstream many
ok ~5.67 s (5 s + 673399368 ns)

# hyperstream small file
ok ~946 ms (0 s + 946487806 ns)

# hstream single
ok ~1.16 s (1 s + 159528184 ns)

# hstream many
ok ~951 ms (0 s + 951094352 ns)

# hstream small file
ok ~70 ms (0 s + 70058016 ns)

all benchmarks completed
ok ~14 s (14 s + 181804772 ns)