Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-url

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-url - npm Package Compare versions

Comparing version 0.0.6 to 0.0.8

src/ZeroServer.js

2

package.json
{
"name": "stream-url",
"version": "0.0.6",
"version": "0.0.8",
"homepage": "http://github.com/gritzko/stream-url",

@@ -5,0 +5,0 @@ "repository": {

@@ -5,3 +5,3 @@ Stream URLs

The package aims to unite two powerful universal concepts: streams and
URLs. It is mostly driven by desire to create modular istributed
URLs. It is mostly driven by desire to create modular distributed
applications connected by asynchronous interfaces.

@@ -36,3 +36,3 @@ Consider typical microservices. Those are connected by HTTP

listening at the `url`, using `options`. Invoke `callback` when
ready. The server will emit `connection` event for every new
ready. The server will emit a `connection` event for every new
incoming connection/stream.

@@ -39,0 +39,0 @@ * `connect(url [,options] [,callback])` connect to a server at (create

"use strict";
var url = require('url');
var ZeroServer = require('./ZeroServer');
var ZeroStream = require('./ZeroStream');

@@ -13,3 +15,7 @@ var adaptors;

// and emits 'connection' event
function listen (stream_url, callback) {
function listen (stream_url, options, callback) {
if (options && options.constructor===Function) {
callback = options;
options = undefined;
}
var u = url.parse(stream_url.toString());

@@ -20,7 +26,11 @@ var adaptor = adaptors[u.protocol];

}
return adaptor.listen(u, callback);
return adaptor.listen(u, options, callback);
}
// returns a stream, either immediately or through the callback
function connect (stream_url, callback) {
function connect (stream_url, options, callback) {
if (options && options.constructor===Function) {
callback = options;
options = undefined;
}
var u = url.parse(stream_url.toString());

@@ -31,3 +41,3 @@ var adaptor = adaptors[u.protocol];

}
return adaptor.connect(u, callback);
return adaptor.connect(u, options, callback);
}

@@ -37,2 +47,3 @@

adaptors[protocol] = {
protocol: protocol,
listen: listen_handler,

@@ -43,5 +54,3 @@ connect: connect_handler

module.exports = {
var stream_url = module.exports = {
listen: listen,

@@ -51,1 +60,13 @@ connect: connect,

};
stream_url.register('0:', zero_listen, zero_connect);
function zero_listen (stream_url, options, callback) {
return new ZeroServer(stream_url, options, callback);
}
function zero_connect (stream_url, options, callback) {
var stream = new ZeroStream();
stream.connect(stream_url, options, callback);
return stream;
}
"use strict";
var su = require('..');
var bat = require('swarm-bat'); // register loopback:

@@ -8,20 +7,43 @@ var tape = require('tape');

var tape_dom = require('tape-dom');
tape_dom.installCSS();
tape_dom.stream(tape);
}
tape ('1.A listen-connect loopback stream', function (t) {
t.plan(3);
var server = su.listen('loopback:string', function(stream) {
t.ok(true, 'incoming connection');
stream.write('OK');
stream.end();
tape ('1.A listen-connect for direct-invocation streams', function (t) {
var dummy_object = {dummy:'object'}, serv_rem;
t.plan(8);
var server = su.listen('0:string', function(err, serv) {
serv_rem = serv;
t.notOk(err, 'no errors');
serv.on('connection', function(conn) {
t.pass('incoming connection');
conn.on('data', function (obj) {
t.ok(obj===dummy_object, 'object received');
});
conn.write('OK');
conn.end();
});
});
var one = su.connect('loopback:string', function (stream) {
t.ok(server===serv_rem);
var one = su.connect('0://string', function (err, stream) {
t.notOk(err);
t.ok(one===stream);
stream.on('data', function (data) {
t.equal(''+data, 'OK', 'data match');
t.equal(data, 'OK', 'data match');
});
stream.on('end', function (){
t.ok(true, 'stream ends'); // TODO
t.pass('stream ends'); // TODO
t.end();
});
stream.write(dummy_object);
});
});
tape ('1.B connect fail', function (t) {
t.plan(2);
su.connect('0:nonexisting', function (err, stream) {
t.ok(err, 'got an error');
t.notOk(stream, 'no stream');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc