JSPM

bun

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 403794
  • Score
    100M100P100Q177359F
  • License BSD

A useful container for streams

Package Exports

  • bun

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 (bun) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bun build status

We've all pondered, "But what do I do with it?" The answer is universal: Wrap it in a bun! bun wraps a series of streams into a single stream.Duplex-compliant unit.

A Possible And Likely Scenario

Say you have an existing module with an implentation like this

// my-transport.js
encryptor.pipe(compressor).pipe(socket).pipe(decompressor).pipe(decryptor);

Totally believable, right? Now each time someone wants to use your module, you have to do something like this

// too much work!
client.pipe(encryptor)
      .pipe(compressor)
      .pipe(socket)
      .pipe(decompressor)
      .pipe(decryptor)
      .pipe(client);

Gross! Puke! This is horribly inconvenient and ugly for the end user! Let's look at a better solution

// defined in my-transport.js
module.service = bun(encryptor, compressor, socket, decompressor, decryptor);

// used in client
var transport = require("./my-transport");
client.pipe(transport.service).pipe(client);

Hot cross buns! bun is amazing!

Example

var  stream = require("stream"),
     bun    = require("bun");

// stream generator
var createStream = function createStream(id) {
  var s = new stream.Transform({encoding: "utf8"});
  s._transform = function _transform(str, encoding, done) {
    this.push("(" + id + " " + str + ")");
    done();
  };
  return s;
};

// create some streams
var streams = ["G", "O", "D"].map(function(id) {
  return createStream(id);
});

// wrap the streams in a bun!
var hotdog = bun(streams);

// connect hotdog to stdout
hotdog.pipe(process.stdout);

// use the hotdog
hotdog.write("in a bun"); // (D (O (G in a bun)))

Buns are convenient, edible, and keep your hands clean! Use bun!

API

bun

var service = bun(streams);
  • streams - An array of stream objects.