From 443e0d7af4c405dfcecfc379924f23c3cd7a288b Mon Sep 17 00:00:00 2001 From: Tim-Smart Date: Tue, 31 Aug 2010 15:54:57 +1200 Subject: [PATCH] Now using node base64 --- build.sh | 3 - clean.sh | 4 - lib/twitter-node/index.js | 6 +- package.json | 9 +- test/twitter_node_config_test.js | 6 +- vendor/node-base64/README.md | 39 ---- vendor/node-base64/base64.cc | 218 ------------------ .../node-base64/js_base64_for_comparsion.js | 81 ------- vendor/node-base64/makefile | 8 - vendor/node-base64/test.js | 51 ---- vendor/node-base64/test.php | 14 -- vendor/node-base64/wscript | 18 -- 12 files changed, 8 insertions(+), 449 deletions(-) delete mode 100755 build.sh delete mode 100755 clean.sh delete mode 100644 vendor/node-base64/README.md delete mode 100644 vendor/node-base64/base64.cc delete mode 100644 vendor/node-base64/js_base64_for_comparsion.js delete mode 100644 vendor/node-base64/makefile delete mode 100644 vendor/node-base64/test.js delete mode 100644 vendor/node-base64/test.php delete mode 100644 vendor/node-base64/wscript diff --git a/build.sh b/build.sh deleted file mode 100755 index d4f75dec..00000000 --- a/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -cd vendor/node-base64 -node-waf configure build -cp build/default/base64.node ../../lib/twitter-node/ diff --git a/clean.sh b/clean.sh deleted file mode 100755 index 5798c6f4..00000000 --- a/clean.sh +++ /dev/null @@ -1,4 +0,0 @@ -rm lib/twitter-node/base64.node -rm vendor/node-base64/.lock-wscript -rm -Rf vendor/node-base64/build - diff --git a/lib/twitter-node/index.js b/lib/twitter-node/index.js index 55788624..1c37d086 100644 --- a/lib/twitter-node/index.js +++ b/lib/twitter-node/index.js @@ -1,8 +1,8 @@ var http = require('http'), - b64 = require('./base64'), query = require('querystring'), Parser = require('./parser'), - EventEmitter = require('events').EventEmitter; + EventEmitter = require('events').EventEmitter, + Buffer = require('buffer').Buffer; // process.mixin is gone, a function for replacement function extend(a, b) { @@ -189,7 +189,7 @@ TwitterNode.prototype.buildParams = function() { // // Returns a Basic Auth header fit for HTTP. var basicAuth = function basicAuth(user, pass) { - return "Basic " + b64.encode(user + ":" + pass); + return "Basic " + new Buffer(user + ":" + pass).toString('base64'); }; // Creates a callback for the object Event of the JSON Parser. diff --git a/package.json b/package.json index 29cf2ef3..a73c2066 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,6 @@ "type": "git", "url": "http://github.com/technoweenie/twitter-node.git" }, - "engine": [ "node >=0.1.99" ], - "scripts": { - "preinstall": "./build.sh" - }, - "directories": { - "lib": "./lib/twitter-node" - } + "engine": [ "node >=0.2.0" ], + "main": "./lib/twitter-node" } diff --git a/test/twitter_node_config_test.js b/test/twitter_node_config_test.js index d1a0d6f3..5968bad0 100644 --- a/test/twitter_node_config_test.js +++ b/test/twitter_node_config_test.js @@ -1,4 +1,4 @@ -var TwitterNode = require('../lib').TwitterNode, +var TwitterNode = require('../lib/twitter-node').TwitterNode, assert = require('assert'), sys = require('sys'); @@ -6,7 +6,7 @@ process.mixin(GLOBAL, require('ntest')); describe("streaming json parser") it("accepts JSON in chunks", function() { - var parser = require("../lib/streaming_json_parser"), + var parser = require("../lib/twitter-node/parser"), p = new parser.instance(), result @@ -150,4 +150,4 @@ describe("custom TwitterNode instance") it("sets host", function() { assert.equal(this.options.host, this.twit.host) - }) \ No newline at end of file + }) diff --git a/vendor/node-base64/README.md b/vendor/node-base64/README.md deleted file mode 100644 index 92d0295f..00000000 --- a/vendor/node-base64/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# node-base64 -* C/C++ library for encode and decode in base 64 - - -## Install: -### way 1 -1) go to the directory with node-base64 library - -2) execute `node-waf configure build` - -3) get module from `./build/default/base64.node` - -You should use `var base64 = require("./build/default/base64");` (way to module) - -### way 2 (works if node are installed in default path) -1) go to the directory with node-base64 library - -2) execute `make` - -3) execute `sudo make install` - -You should use `var base64 = require("base64");` (from any path) - -## Functions: - encode(str); // Encode string - decode(str); // Decode string - -## Usage: - var base64 = require('base64'); - var code = base64.encode('text'); - var str = base64.decode(code); // text - -## Speed testing -To run speed test on your computer run test.js, here is my: - C++ base64 result is: 82 - JS base64 result is: 517 - C++ module faster than JS in 6.304878048780488 times - - diff --git a/vendor/node-base64/base64.cc b/vendor/node-base64/base64.cc deleted file mode 100644 index ef2b87ba..00000000 --- a/vendor/node-base64/base64.cc +++ /dev/null @@ -1,218 +0,0 @@ -/** - * nodejs(http://github.com/ry/node/) library for base64 encoding(decoding) - * - * @package base64 - * @link http://github.com/brainfucker/node-base64 - * @autor Oleg Illarionov - * @version 1.0 - */ - -#include -#include -#include - -#include -#include -#include - -using namespace v8; -using namespace node; - -static const char base64_table[] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' -}; - -static const char base64_pad = '='; - -static const short base64_reverse_table[256] = { - -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -2, -1, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2, - -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2, - -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 -}; - - -char* base64_encode(const unsigned char *str, int length, int *ret_length) /* {{{ */ -{ - const unsigned char *current = str; - char *p; - char *result; - - if ((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) { - if (ret_length != NULL) { - *ret_length = 0; - } - return NULL; - } - - result = (char *)malloc((((length + 2) / 3) * 4)*(sizeof(char))+(1)); - if (result == NULL) { - fprintf(stderr, "out of memory!\n"); - exit(1); - } - p = result; - - while (length > 2) { - *p++ = base64_table[current[0] >> 2]; - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; - *p++ = base64_table[current[2] & 0x3f]; - - current += 3; - length -= 3; - } - - if (length != 0) { - *p++ = base64_table[current[0] >> 2]; - if (length > 1) { - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[(current[1] & 0x0f) << 2]; - *p++ = base64_pad; - } else { - *p++ = base64_table[(current[0] & 0x03) << 4]; - *p++ = base64_pad; - *p++ = base64_pad; - } - } - if (ret_length != NULL) { - *ret_length = (int)(p - result); - } - *p = '\0'; - return result; -} - - -char *base64_decode(const unsigned char *str, int length, int *ret_length) -{ - const unsigned char *current = str; - int ch, i = 0, j = 0, k; - char *result; - - result = (char *)malloc(length+1); - if (result == NULL) { - fprintf(stderr, "out of memory!\n"); - exit(1); - } - - while ((ch = *current++) != '\0' && length-- > 0) { - if (ch == base64_pad) { - if (*current != '=' && (i % 4) == 1) { - free(result); - return NULL; - } - continue; - } - - ch = base64_reverse_table[ch]; - if ((1 && ch < 0) || ch == -1) { - continue; - } else if (ch == -2) { - free(result); - return NULL; - } - - switch(i % 4) { - case 0: - result[j] = ch << 2; - break; - case 1: - result[j++] |= ch >> 4; - result[j] = (ch & 0x0f) << 4; - break; - case 2: - result[j++] |= ch >>2; - result[j] = (ch & 0x03) << 6; - break; - case 3: - result[j++] |= ch; - break; - } - i++; - } - - k = j; - - if (ch == base64_pad) { - switch(i % 4) { - case 1: - free(result); - return NULL; - case 2: - k++; - case 3: - result[k] = 0; - } - } - if(ret_length) { - *ret_length = j; - } - result[j] = '\0'; - return result; -} - - -Handle -base64_encode_binding(const Arguments& args) -{ - HandleScope scope; - int len; - Local ret; - if (Buffer::HasInstance(args[0])) { - Buffer *buffer = ObjectWrap::Unwrap(args[0]->ToObject()); - char *str = base64_encode((unsigned char*)buffer->data(), buffer->length(),&len); - ret = String::New(str, len); - delete str; - } else { - String::Utf8Value data(args[0]->ToString()); - char* str = base64_encode((unsigned char*)*data,data.length(),&len); - ret = String::New(str,len); - delete str; - } - return ret; -} - - -Handle -base64_decode_binding(const Arguments& args) -{ - HandleScope scope; - Local ret; - int len; - if (Buffer::HasInstance(args[0])) { - Buffer *buffer = ObjectWrap::Unwrap(args[0]->ToObject()); - char *str = base64_decode((unsigned char*)buffer->data(), buffer->length(),&len); - ret = String::New(str, len); - delete str; - } else { - String::Utf8Value data(args[0]->ToString()); - char* str=base64_decode((unsigned char*)*data,data.length(),&len); - ret = String::New(str,len); - delete str; - } - return ret; -} - - -extern "C" void init (Handle target) -{ - HandleScope scope; - - target->Set(String::New("encode"), FunctionTemplate::New(base64_encode_binding)->GetFunction()); - target->Set(String::New("decode"), FunctionTemplate::New(base64_decode_binding)->GetFunction()); -} diff --git a/vendor/node-base64/js_base64_for_comparsion.js b/vendor/node-base64/js_base64_for_comparsion.js deleted file mode 100644 index 7d5bc586..00000000 --- a/vendor/node-base64/js_base64_for_comparsion.js +++ /dev/null @@ -1,81 +0,0 @@ - var keyStr = "ABCDEFGHIJKLMNOP" + - "QRSTUVWXYZabcdef" + - "ghijklmnopqrstuv" + - "wxyz0123456789+/" + - "="; -exports.encode = function(input) { - input = escape(input); - var output = ""; - var chr1, chr2, chr3 = ""; - var enc1, enc2, enc3, enc4 = ""; - var i = 0; - - do { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - - enc1 = chr1 >> 2; - enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - enc4 = chr3 & 63; - - if (isNaN(chr2)) { - enc3 = enc4 = 64; - } else if (isNaN(chr3)) { - enc4 = 64; - } - - output = output + - keyStr.charAt(enc1) + - keyStr.charAt(enc2) + - keyStr.charAt(enc3) + - keyStr.charAt(enc4); - chr1 = chr2 = chr3 = ""; - enc1 = enc2 = enc3 = enc4 = ""; - } while (i < input.length); - - return output; - } - -exports.decode = function(input) { - var output = ""; - var chr1, chr2, chr3 = ""; - var enc1, enc2, enc3, enc4 = ""; - var i = 0; - - // remove all characters that are not A-Z, a-z, 0-9, +, /, or = - var base64test = /[^A-Za-z0-9\+\/\=]/g; - if (base64test.exec(input)) { - alert("There were invalid base64 characters in the input text.\n" + - "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" + - "Expect errors in decoding."); - } - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); - - do { - enc1 = keyStr.indexOf(input.charAt(i++)); - enc2 = keyStr.indexOf(input.charAt(i++)); - enc3 = keyStr.indexOf(input.charAt(i++)); - enc4 = keyStr.indexOf(input.charAt(i++)); - - chr1 = (enc1 << 2) | (enc2 >> 4); - chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - chr3 = ((enc3 & 3) << 6) | enc4; - - output = output + String.fromCharCode(chr1); - - if (enc3 != 64) { - output = output + String.fromCharCode(chr2); - } - if (enc4 != 64) { - output = output + String.fromCharCode(chr3); - } - - chr1 = chr2 = chr3 = ""; - enc1 = enc2 = enc3 = enc4 = ""; - - } while (i < input.length); - - return unescape(output); - } diff --git a/vendor/node-base64/makefile b/vendor/node-base64/makefile deleted file mode 100644 index 3a83cdbb..00000000 --- a/vendor/node-base64/makefile +++ /dev/null @@ -1,8 +0,0 @@ -all: - node-waf configure build -tests: - node ./test.js -install: - cp ./build/default/base64.node /usr/local/lib/node/libraries/base64.node -clean: - rm -rf ./build diff --git a/vendor/node-base64/test.js b/vendor/node-base64/test.js deleted file mode 100644 index 79bee58e..00000000 --- a/vendor/node-base64/test.js +++ /dev/null @@ -1,51 +0,0 @@ -var base64 = require("./build/default/base64"), - jsbase64 = require("./js_base64_for_comparsion"), - Buffer = require('buffer').Buffer, - sys = require("sys"); - -//sys.puts(base64.encode('wow')); -var textBuff = new Buffer('What do ya want for nothing?', 'utf8'); -var baseBuff = new Buffer('V2hhdCBkbyB5YSB3YW50IGZvciBub3RoaW5nPw==', 'utf8'); - -if (base64.encode('What do ya want for nothing?')=='V2hhdCBkbyB5YSB3YW50IGZvciBub3RoaW5nPw==') - sys.puts('test 1 PASSED'); -else - sys.puts('test 1 FAILS'); - -if (base64.decode(base64.encode('What do ya want for nothing?'))=='What do ya want for nothing?') - sys.puts('test 2 PASSED'); -else - sys.puts('test 2 FAILS'); - -if (base64.encode(textBuff)=='V2hhdCBkbyB5YSB3YW50IGZvciBub3RoaW5nPw==') - sys.puts('test 3 PASSED'); -else - sys.puts('test 3 FAILS'); - -if (base64.decode(baseBuff)=='What do ya want for nothing?') - sys.puts('test 4 PASSED'); -else - sys.puts('test 4 FAILS'); - - -// C++ base64 -var m1=new Date().getTime(); -for(i=0;i<10000;i++) { - h=base64.decode(base64.encode('EdPy2H71Q1MjTzkuRxAr1CJWs2ZapZEuaY3XwJL8mpxaTBLWZPkw1yakKLv2r79eHmNQ1m2Cc6PErAkH5FR3Nmd011F09LCas76Z'+String(i))); -} -var m2=new Date().getTime(); -var c=m2-m1; -sys.puts('C++ base64 result is: '+(c)); - - -// JS base64 -var m1=new Date().getTime(); -for(i=0;i<10000;i++) { - h=jsbase64.decode(jsbase64.encode('EdPy2H71Q1MjTzkuRxAr1CJWs2ZapZEuaY3XwJL8mpxaTBLWZPkw1yakKLv2r79eHmNQ1m2Cc6PErAkH5FR3Nmd011F09LCas76Z'+String(i))); -} -var m2=new Date().getTime(); -var js=m2-m1; -sys.puts('JS base64 result is: '+(js)); -if (cjs) sys.puts('JS module faster than C++ in '+(c/j)+' times'); - diff --git a/vendor/node-base64/test.php b/vendor/node-base64/test.php deleted file mode 100644 index 4bff0de6..00000000 --- a/vendor/node-base64/test.php +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/vendor/node-base64/wscript b/vendor/node-base64/wscript deleted file mode 100644 index 6d73dd64..00000000 --- a/vendor/node-base64/wscript +++ /dev/null @@ -1,18 +0,0 @@ -srcdir = "." -blddir = "build" -VERSION = "0.0.1" - -def set_options(opt): - opt.tool_options("compiler_cxx") - opt.tool_options("compiler_cc") - -def configure(conf): - conf.check_tool("compiler_cxx") - conf.check_tool("compiler_cc") - conf.check_tool("node_addon") - conf.env.append_value('CCFLAGS', ['-O3']) - -def build(bld): - obj = bld.new_task_gen("cxx", "shlib", "node_addon") - obj.target = "base64" - obj.source = "base64.cc"