Socket
Book a DemoInstallSign in
Socket

turtles

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turtles

adds stream passing support to dnode callbacks

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

Build Status

turtles

turtles: callback streams for dnode

Adds stream passing support for dnode callbacks. i use it with dnode on top of shoe. readable/writeable/duplex stream support in one!

For those unfamiliar with dnode. dnode is a really great way to treat your server like a module.

examples

pipe a file


var t1 = turtles({
  lines:function(cb){
    var stream = fs.createReadStream('file.txt')
      .pipe(linestream())// parse it to lines of text
      .pipe(this.stream());

    cb(false,stream);
  }
});

t2 = turtles();

t2.on('remote',function(remote){
    remote.lines(function(err,stream){
      stream.on('data',function(line){
        console.log('a line:',line);
      })
    });
});

t2.pipe(t1).pipe(t2);

todo: shoe/engine.io-stream example

api

the api extends dnode with exactly one method

  • turtles.stream()
    • returns a duplex stream
    • a stream is not cleaned up until both sides close. if you dont use one side it will be closed automatically for you.
    • if you only read from this stream and it ends is will close the write side for you and cleanup the stream.
    • if you only write from this stream and it ends is will close the read side for you and cleanup the stream.
    • you may pass these as data arguments to callbacks

the api reserves the name of one callback _turtles

thanks

@substack for making awesome stuff! and for hopefully giving me permission to use the turtle picture.

inception!

dnode over dnode

var turtles = require('turtles');

var value;

var oneTurtle = turtles({
  setValue:function(v){
    value = v;
  },
  moarTurtles:function(cb){
    var dnode = turtles({
      dnodeOnDnode:function(cb){
        cb(false,value)
      }
    });

    var stream = this.stream();

    stream.pipe(dnode).pipe(stream);

    dnode.on('remote',function(remote){
      remote.twoTurtleJiveTime(function(err,data){
        console.log(data);
        //
        // prints 'got the two turtle jive!'
        //
      });
    });

    cb(false,stream);

  }
})

var twoTurtle = turtles({});

twoTurtle.on('remote',function(remote){

  var firstTurtle = remote;

  remote.moarTurtles(function(err,stream){
    var dnode = turtles({
      twoTurtleJiveTime:function(cb){
        cb(false,'got the two turtle jive!');
      }
    });


    dnode.on('remote',function(remote){
      firstTurtle.setValue('ballerz')
      remote.dnodeOnDnode(function(err,data){
        console.log(data);
        //
        // prints 'ballerz'
        //
      });
    }); 

    dnode.pipe(stream).pipe(dnode);

  });
});

oneTurtle.pipe(twoTurtle).pipe(oneTurtle);

FAQs

Package last updated on 21 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts