Guest User

Untitled

a guest
Jan 3rd, 2013
2,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. var http = require('http');
  2. var fs = require('fs');
  3. var async = require('async');
  4.  
  5. //downloadModule("functionChecker.js");
  6. async.series({
  7. functionChecker: function(callback){
  8. downloadModule('javascript-modules.googlecode.com/svn/functionChecker.js', callback); //this gets
  9. },
  10. //stuff: function(callback){
  11. //downloadModule("stuff.js", callback); //this gets
  12. //}
  13. },
  14. function(err, results){
  15. results.functionChecker.checkAllFunctions(__filename);
  16. });
  17.  
  18. function getHostName(theString){
  19. return theString.substring(0, theString.indexOf("/"));
  20. }
  21.  
  22. function getPath(theString){
  23. return theString.substring(getHostName(theString).length, theString.length);
  24. }
  25.  
  26. function getFileName(theString){
  27. return theString.substring(theString.lastIndexOf("/"), theString.length);
  28. }
  29.  
  30. function downloadModule(filename, callback) {
  31. http.get({
  32. hostname: getHostName(filename),
  33. path: getPath(filename)
  34. }, function(res){
  35. var out = fs.createWriteStream(__dirname + "/downloadedModules/" + getFileName(filename));
  36. out.on('close', function(){
  37. //this is where you use the module that was downloaded
  38. var returnThis = require(__dirname + "/downloadedModules/" + getFileName(filename));
  39. callback(null, returnThis); //"return" returnThis so that it can be used in the final callback of async.series
  40. });
  41. res.pipe(out);
  42. });
  43. }
  44.  
  45. //function name: blahblah
  46. //requires functions: false
  47. //is defined: false
  48. //description: blah
Advertisement
Add Comment
Please, Sign In to add comment