npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

split-join

v0.0.8

Published

Split -> Join Streams

Downloads

12

Readme

Split -> Join Streams

Build Status

NPM

A pair of streams and a cache to facilitate serialization and deserialization of javascript objects.

Classes

  • Split
  • Join
  • Cache

Split - abstract interface (stream)

This class must be extended and split(obj) method must be implemented. The split(obj) method must serialize the obj into array of packets and the result must be cached with unique ID string. Must return the ID.

Join - abstract interface (stream)

This class must be extended and join(packet) method must be implemented. At every execution the join(packet) method must create an array of the chunks which make up the original obj and cache it with unique ID string.
If the array contains enough packets to reassemble the original obj, the
join(packet) method must return the ID, otherwise, it must return null

Usage (CoffeeScript)

Implement Split (provided as requireable simple.Split)

class Split extends (require 'split-join').Split
  split: (obj) ->
    if @cache.isFull then throw new Error 'Cache is full'
    chunksId = Math.random().toString(36)
    @cache.add chunksId, chunks = (JSON.stringify obj).match /.{1,256}/g
    total = chunks.length
    for chunk, index in chunks
      chunks[index] = "#{chunksId} #{index} #{total}\n\n#{chunk}"
    return chunksId

Implement Join (provided as requireable simple.Join)

class Join extends (require 'split-join').Join
  regexp = /^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s*?\n\n(.+)$/m
  join: (packet) ->
    if parsed = packet.toString().match regexp
      [id, index, total, chunk] = parsed[1..4]
    unless chunks = @cache.get id
      if @cache.isFull then throw new Error 'Cache is full'
      @cache.add id, chunks = []
    chunks.push chunk
    if (parseInt index) + 1 is (parseInt total)
      return id
    return

Sender

socket = getSocketSomehow()
split = new Split
split.pipe socket

# serialize the array into packets and send them out
split.write [ 'data', 'from', 'sender' ]

Receiver

socket = getSocketSomehow()
join = new Join
socket.pipe join

# the data coming from join will be the array from the sender