NewsBlur/node/node_modules/stream-length/test.js
2019-04-13 15:11:58 -04:00

61 lines
2 KiB
JavaScript

// Generated by CoffeeScript 1.8.0
(function() {
var Promise, fs, http, request, streamLength;
streamLength = require("./");
fs = require("fs");
request = require("request");
http = require("http");
Promise = require("bluebird");
Promise["try"](function() {
console.log("Length of fs:README.md...");
return streamLength(fs.createReadStream("README.md"));
}).then(function(length) {
return console.log("Length", length);
})["catch"](function(err) {
return console.log("No-Length", err);
}).then(function() {
console.log("Length of Buffer...");
return streamLength(new Buffer("testing buffer content length retrieval..."));
}).then(function(length) {
return console.log("Length", length);
})["catch"](function(err) {
return console.log("No-Length", err);
}).then(function() {
console.log("Length of http:Google");
return new Promise(function(resolve, reject) {
return http.get("http://www.google.com/images/srpr/logo11w.png", function(res) {
return resolve(res);
}).on("error", function(err) {
return reject(err);
});
});
}).then(function(res) {
res.resume();
return streamLength(res);
}).then(function(length) {
return console.log("Length", length);
})["catch"](function(err) {
return console.log("No-Length", err);
}).then(function() {
console.log("Length of request:Google...");
return streamLength(request("http://www.google.com/images/srpr/logo11w.png", function(err, res, body) {}));
}).then(function(length) {
return console.log("Length", length);
})["catch"](function(err) {
return console.log("No-Length", err);
}).then(function() {
console.log("Length of request:Google:fail...");
return streamLength(request("http://www.google.com/", function(err, res, body) {}));
}).then(function(length) {
return console.log("Length", length);
})["catch"](function(err) {
return console.log("No-Length", err);
});
}).call(this);