New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

streamline

Package Overview
Dependencies
Maintainers
0
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streamline - npm Package Compare versions

Comparing version 0.1.17 to 0.1.18

examples/.svn/text-base/googleClient_.js.svn-base

9

examples/googleClient_.js

@@ -13,11 +13,8 @@ /*

// The options are the same as for node's http.request call.
// But the call also accepts a simple URL for the GET case
// But httpw.request does not take any callback parameter.
// Instead, the callback is passed to the end method (a few lines below).
var req = streams.httpRequest({
//host: 'www.google.com',
host: 'ajax.googleapis.com',
port: 80,
//path: '/search?q=' + str,
path: '/ajax/services/search/web?v=1.0&q=' + str,
method: 'GET'
url: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' + str,
proxy: process.env.http_proxy
});

@@ -24,0 +21,0 @@

@@ -17,22 +17,20 @@ /*** Generated by streamline 0.1.16 - DO NOT EDIT ***/

var __then = _;
/* 15 */ var req = streams.httpRequest({
/* 17 */ host: "ajax.googleapis.com",
/* 18 */ port: 80,
/* 20 */ path: ("/ajax/services/search/web?v=1.0&q=" + str),
/* 21 */ method: "GET"
/* 16 */ var req = streams.httpRequest({
/* 17 */ url: ("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + str),
/* 18 */ proxy: process.env.http_proxy
});
/* 28 */ return req.end().response(__cb(_, function(__0, resp) {
/* 30 */ return resp.checkStatus(200).readAll(__cb(_, function(__0, __2) {
/* 30 */ return _(null, JSON.parse(__2));
/* 25 */ return req.end().response(__cb(_, function(__0, resp) {
/* 27 */ return resp.checkStatus(200).readAll(__cb(_, function(__0, __2) {
/* 27 */ return _(null, JSON.parse(__2));
}));
}));
};
/* 34 */ var str = ((process.argv.length > 2) ? process.argv[2] : "node.js");
/* 37 */ return google(str, __cb(_, function(__0, result) {
/* 40 */ var formatted = result.responseData.results.map(function __1(entry) {
/* 41 */ return ((entry.url + "\n ") + entry.titleNoFormatting);
/* 42 */ }).join("\n");
/* 43 */ console.log(formatted);
/* 31 */ var str = ((process.argv.length > 2) ? process.argv[2] : "node.js");
/* 34 */ return google(str, __cb(_, function(__0, result) {
/* 37 */ var formatted = result.responseData.results.map(function __1(entry) {
/* 38 */ return ((entry.url + "\n ") + entry.titleNoFormatting);
/* 39 */ }).join("\n");
/* 40 */ console.log(formatted);
return __then();
}));
})();

@@ -10,3 +10,3 @@ /*** Generated by streamline 0.1.16 - DO NOT EDIT ***/

function __trap(err) { if (err) { if (__global.__context && __global.__context.errorHandler) __global.__context.errorHandler(err); else console.error("UNCAUGHT EXCEPTION: " + err.message + "\n" + err.stack); } }
var http = require("http");
var parseUrl = require("url").parse;
function _reply(callback, err, value) {

@@ -19,49 +19,56 @@ try {

};
function InputStreamWrapper(stream, options) {
function checkOpen(stream) {
if (!stream) {
throw new Error("invalid operation on closed stream")
};
};
function ReadableStream(stream, options) {
options = (options || {
});
var lowMark = Math.max((options.lowMark || 0), 0);
var highMark = Math.max((options.highMark || 0), lowMark);
var paused = false;
var current = 0;
var chunks = [];
var error;
var done = false;
var _low = Math.max((options.lowMark || 0), 0);
var _high = Math.max((options.highMark || 0), _low);
var _paused = false;
var _current = 0;
var _chunks = [];
var _error;
var _done = false;
var _encoding;
var _chunk;
stream.on("error", function __1(err) {
onEvent(err);
_onData(err);
});
stream.on("data", function __2(chunk) {
onEvent(null, chunk);
_onData(null, chunk);
});
stream.on("end", function __3() {
onEvent(null, null);
_onData(null, null);
});
var trackEvent = function __4(err, chunk) {
stream.on("close", function __4() {
stream = null;
});
function trackData(err, chunk) {
if (err) {
error = err;
_error = err;
} else {
if (chunk) {
chunks.push(chunk);
current += chunk.length;
if (((current > highMark) && !paused)) {
_chunks.push(chunk);
_current += chunk.length;
if (((((_current > _high) && !_paused) && !_done) && !_error)) {
stream.pause();
paused = true;
_paused = true;
}
;
}
else done = true;
else _done = true;
};
};
var onEvent = trackEvent;
this.read = function read(callback) {
if (!callback) {
return __future.call(this, read, arguments, 0)
};
if ((chunks.length > 0)) {
var chunk = chunks.splice(0, 1)[0];
current -= chunk.length;
if (((current <= lowMark) && paused)) {
var _onData = trackData;
function readChunk(callback) {
if ((_chunks.length > 0)) {
var chunk = _chunks.splice(0, 1)[0];
_current -= chunk.length;
if (((((_current <= _low) && _paused) && !_done) && !_error)) {
stream.resume();
paused = false;
_paused = false;
}

@@ -71,10 +78,17 @@ ;

}
else if (done) {
else if (_done) {
return _reply(callback, null, null);
} else {
if (error) {
return _reply(callback, error);
if (_error) {
return _reply(callback, _error);
} else {
onEvent = function __1(err, chunk) {
onEvent = trackEvent;
_onData = function __1(err, chunk) {
if (err) {
_error = err;
} else {
if (!chunk) {
_done = true;
}
};
_onData = trackData;
_reply(callback, err, chunk);

@@ -86,15 +100,77 @@ };

};
this.readAll = function __5(_) {
function concat(chunks, total) {
if (_encoding) {
return chunks.join("")
};
if ((chunks.length == 1)) {
return chunks[0]
};
var result = new Buffer(total);
chunks.reduce(function __1(val, chunk) {
chunk.copy(result, val);
return (val + chunk.length);
}, 0);
return result;
};
this.setEncoding = function __5(enc) {
checkOpen(stream);
_encoding = enc;
if (enc) {
stream.setEncoding(enc);
};
return this;
};
this.read = function __6(_, len) {
if (!_) {
return __future.call(this, __5, arguments, 0);
return __future(__6, arguments, 0);
}
;
var __then = _;
var chunk, chunks = [];
return function(__break) {
var __loop = __nt(_, function() {
var __then = __loop;
return this.read(__cb(_, function(__0, __1) {
if (chunk = __1) {
chunks.push(chunk);
if (!stream) {
return _(null, null)
};
return function(__then) {
if ((len == null)) {
return readChunk(_);
}
;
return __then();
}(function() {
if ((len < 0)) {
len = Infinity;
};
if ((len == 0)) {
return _(null, (_encoding ? "" : new Buffer(0)))
};
var chunks = [], total = 0;
return function(__break) {
var __loop = __nt(_, function() {
var __then = __loop;
if ((total < len)) {
return function(__then) {
if (!_chunk) {
return readChunk(__cb(_, function(__0, __2) {
_chunk = __2;
return __then();
}));
}
;
return __then();
}(function() {
if (!_chunk) {
return _(null, ((chunks.length == 0) ? null : concat(chunks, total)))
};
if (((total + _chunk.length) <= len)) {
chunks.push(_chunk);
total += _chunk.length;
_chunk = null;
}
else {
chunks.push(_chunk.slice(0, (len - total)));
_chunk = _chunk.slice((len - total));
total = len;
}
;
return __then();
});
}

@@ -105,33 +181,81 @@ else {

;
return __then();
}.bind(this)));
}.bind(this));
return __loop();
}.call(this, function() {
return _(null, chunks.join(""));
}.bind(this));
});
return __loop();
}(function() {
return _(null, concat(chunks, total));
});
});
};
this.readAll = function __7(_) {
if (!_) {
return __future.call(this, __7, arguments, 0);
}
;
var __then = _;
return this.read(_, -1);
};
this.__defineGetter__("stream", function __8() {
return stream;
});
};
function ServerRequestWrapper(req, options) {
InputStreamWrapper.call(this, req, options);
this._req = req;
exports.ReadableStream = ReadableStream;
function WritableStream(stream, options) {
options = (options || {
});
stream.on("close", function __1() {
stream = null;
});
this.write = function __2(data, enc) {
checkOpen(stream);
stream.write(data, enc);
return this;
};
this.end = function __3(data, enc) {
checkOpen(stream);
stream.end(data, enc);
return this;
};
this.__defineGetter__("stream", function __4() {
return stream;
});
};
exports.WritableStream = WritableStream;
function ServerRequest(req, options) {
ReadableStream.call(this, req, options);
this._request = req;
this.setEncoding(_getEncoding(req.headers));
};
["method","url","headers","trailers","httpVersion","connection","socket",].forEach(function __1(name) {
ServerRequestWrapper.prototype.__defineGetter__(name, function __1() {
return this._req[name];
ServerRequest.prototype.__defineGetter__(name, function __1() {
return this._request[name];
});
});
exports.httpServerRequest = function __2(req, options) {
return new ServerRequestWrapper(req, options);
return new ServerRequest(req, options);
};
function ClientResponseWrapper(resp, options) {
InputStreamWrapper.call(this, resp, options);
this._resp = resp;
function _getEncoding(headers) {
var comps = ((headers["content-type"] || "text/plain")).split(";");
var ctype = comps[0];
for (var i = 1; (i < comps.length); i++) {
var pair = comps[i].split("=");
if (((pair.length == 2) && (pair[0].trim() == "charset"))) {
return pair[1].trim()
};
};
if (((ctype.indexOf("text") >= 0) || (ctype.indexOf("json") >= 0))) {
return "utf8"
};
return null;
};
function ClientResponse(resp, options) {
ReadableStream.call(this, resp, options);
this._response = resp;
this.setEncoding(_getEncoding(resp.headers));
};
["statusCode","headers",].forEach(function __3(name) {
ClientResponseWrapper.prototype.__defineGetter__(name, function __1() {
return this._resp[name];
ClientResponse.prototype.__defineGetter__(name, function __1() {
return this._response[name];
});
});
ClientResponseWrapper.prototype.checkStatus = function __4(statuses) {
ClientResponse.prototype.checkStatus = function __4(statuses) {
if ((typeof statuses === "number")) {

@@ -145,35 +269,112 @@ statuses = [statuses,];

};
function ClientRequestWrapper(options) {
var req = http.request(options, function __1(resp) {
onEvent(null, (resp && new ClientResponseWrapper(resp, options)));
function _fixOptions(options) {
if (!options) {
throw new Error("request error: no options")
};
if ((typeof options === "string")) {
options = {
url: options
};
};
if (options.url) {
var parsed = parseUrl(options.url);
options.protocol = parsed.protocol;
options.host = parsed.hostname;
options.port = parsed.port;
options.path = (parsed.pathname + ((parsed.query ? ("?" + parsed.query) : "")));
}
;
options.protocol = (options.protocol || "http:");
options.port = (options.port || (((options.protocol === "https:") ? 443 : 80)));
options.path = (options.path || "/");
if (!options.host) {
throw new Error("request error: no host")
};
options.method = (options.method || "GET");
options.headers = (options.headers || {
});
var response;
var error;
var done = false;
req.on("error", function __2(err) {
onEvent(err);
options.module = require(options.protocol.substring(0, (options.protocol.length - 1)));
if (options.proxy) {
if ((typeof options.proxy === "string")) {
options.proxy = parseUrl(options.proxy);
options.proxy.host = options.proxy.hostname;
}
;
options.proxy.port = (options.proxy.port || options.port);
if (!options.proxy.host) {
throw new Error("proxy configuration error: no host")
};
options.path = (((((options.protocol + "//") + options.host) + ":") + options.port) + options.path);
options.headers.host = options.host;
options.host = options.proxy.host;
options.port = options.proxy.port;
}
;
return options;
};
function ClientRequest(options) {
options = _fixOptions(options);
var _request = options.module.request(options, function __1(resp) {
_onResponse(null, (resp && new ClientResponse(resp, options)));
});
var trackEvent = function __3(err, resp) {
done = true;
error = err;
response = resp;
WritableStream.call(this, _request, options);
var _response;
var _error;
var _done = false;
_request.on("error", function __2(err) {
_onResponse(err);
});
function trackResponse(err, resp) {
_done = true;
_error = err;
_response = resp;
};
var onEvent = trackEvent;
this.write = function __4(data, enc) {
req.write(data, enc);
return this;
var _onResponse = trackResponse;
this.response = function __3(callback) {
if (!callback) {
return __future.call(this, this.response, arguments, 0)
};
if (_done) {
return _reply(callback, _error, _response);
} else {
_onResponse = function __1(err, resp) {
_reply(callback, err, resp);
};
};
};
this.end = function __5(data, enc) {
req.end(data, enc);
return this;
};
exports.httpRequest = function __5(options) {
return new ClientRequest(options);
};
function NetStream(stream, options) {
ReadableStream.call(this, stream, (options.read || options));
WritableStream.call(this, stream, (options.write || options));
};
var net;
function NetClient(options, args) {
args = Array.prototype.slice.call(arguments, 1);
net = (net || require("net"));
var _connection = net.createConnection.apply(net, args);
var _error;
var _done = false;
_connection.on("error", function __1(err) {
_onConnect(err);
});
_connection.on("connect", function __2() {
_onConnect(null);
});
function trackConnect(err) {
_done = true;
_error = err;
};
this.response = function response(callback) {
var _onConnect = trackConnect;
this.connect = function __3(callback) {
if (!callback) {
return __future.call(this, response, arguments, 0)
return __future.call(this, this.connect, arguments, 0)
};
if (done) {
return _reply(callback, error, response);
if (_done) {
return _reply(callback, _error, new NetStream(_connection, options));
} else {
onEvent = function __1(err, resp) {
_reply(callback, err, resp);
_onConnect = function __1(err) {
_reply(callback, err, new NetStream(_connection, options));
};

@@ -183,4 +384,12 @@ };

};
exports.httpRequest = function __5(options) {
return new ClientRequestWrapper(options);
exports.tcpClient = function __6(port, host, options) {
host = (host || "localhost");
options = (options || {
});
return new NetClient(options, port, host);
};
exports.socketClient = function __7(path, options) {
options = (options || {
});
return new NetClient(options, path);
};
{
"name": "streamline",
"description": "Asynchronous Javascript for dummies",
"version": "0.1.17",
"version": "0.1.18",
"engines": { "node": ">=0.2.1" },

@@ -6,0 +6,0 @@ "dependencies": {},

@@ -101,5 +101,8 @@ ## streamline.js

The `streamline/flows` module contains some utilities to deal with arrays, parallel execution, context propagation, etc.
The `streamline/lib/flows` module contains some utilities to deal with arrays, parallel execution, context propagation, etc.
See the [flows module](https://github.com/Sage/streamlinejs/wiki/Flows-module) wiki page for details.
The `streamline/lib/streams` module contains _pull mode_ wrappers around node streams.
See the [streams module](https://github.com/Sage/streamlinejs/wiki/Streams-module) wiki page for details.
## Resources

@@ -106,0 +109,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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