Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update

  • Loading branch information...
commit f5aa7254a70a0d638d0607b54089d900627d49f9 1 parent e76bdd3
@brainfucker authored
View
38 README.md
@@ -0,0 +1,38 @@
+# node-base64
+* fast 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:
+ will be soon
+
+
+<img src="http://nodejs.ru/img/small.png">
View
BIN  build/.wafpickle-7
Binary file not shown
View
2  build/c4che/build.config.py
@@ -0,0 +1,2 @@
+version = 0x105010
+tools = [{'tool': 'ar', 'tooldir': None, 'funs': None}, {'tool': 'cxx', 'tooldir': None, 'funs': None}, {'tool': 'gxx', 'tooldir': None, 'funs': None}, {'tool': 'compiler_cxx', 'tooldir': None, 'funs': None}, {'tool': 'cc', 'tooldir': None, 'funs': None}, {'tool': 'gcc', 'tooldir': None, 'funs': None}, {'tool': 'compiler_cc', 'tooldir': None, 'funs': None}, {'tool': 'node_addon', 'tooldir': None, 'funs': None}]
View
56 build/c4che/default.cache.py
@@ -0,0 +1,56 @@
+AR = '/usr/bin/ar'
+ARFLAGS = 'rcs'
+CC = ['/usr/bin/gcc']
+CCDEFINES_ST = '-D%s'
+CCFLAGS = ['-O3']
+CCFLAGS_DEBUG = ['-g']
+CCFLAGS_MACBUNDLE = ['-fPIC']
+CCFLAGS_RELEASE = ['-O2']
+CCLNK_SRC_F = ''
+CCLNK_TGT_F = ['-o', '']
+CC_NAME = 'gcc'
+CC_SRC_F = ''
+CC_TGT_F = ['-c', '-o', '']
+CC_VERSION = ('4', '4', '1')
+COMPILER_CC = 'gcc'
+COMPILER_CXX = 'g++'
+CPP = '/usr/bin/cpp'
+CPPFLAGS_NODE = '-DEV_MULTIPLICITY=0'
+CPPPATH_NODE = '/usr/local/include/node'
+CPPPATH_ST = '-I%s'
+CXX = ['/usr/bin/g++']
+CXXDEFINES_ST = '-D%s'
+CXXFLAGS_DEBUG = ['-g']
+CXXFLAGS_RELEASE = ['-O2']
+CXXLNK_SRC_F = ''
+CXXLNK_TGT_F = ['-o', '']
+CXX_NAME = 'gcc'
+CXX_SRC_F = ''
+CXX_TGT_F = ['-c', '-o', '']
+DEST_BINFMT = 'elf'
+DEST_CPU = 'x86_64'
+DEST_OS = 'linux'
+FULLSTATIC_MARKER = '-static'
+LIBPATH_NODE = '/usr/local/lib'
+LIBPATH_ST = '-L%s'
+LIB_ST = '-l%s'
+LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup']
+LINK_CC = ['/usr/bin/gcc']
+LINK_CXX = ['/usr/bin/g++']
+PREFIX = '/usr/local'
+PREFIX_NODE = '/usr/local'
+RANLIB = '/usr/bin/ranlib'
+RPATH_ST = '-Wl,-rpath,%s'
+SHLIB_MARKER = '-Wl,-Bdynamic'
+SONAME_ST = '-Wl,-h,%s'
+STATICLIBPATH_ST = '-L%s'
+STATICLIB_MARKER = '-Wl,-Bstatic'
+STATICLIB_ST = '-l%s'
+macbundle_PATTERN = '%s.bundle'
+program_PATTERN = '%s'
+shlib_CCFLAGS = ['-fPIC', '-DPIC']
+shlib_CXXFLAGS = ['-fPIC', '-DPIC']
+shlib_LINKFLAGS = ['-shared']
+shlib_PATTERN = 'lib%s.so'
+staticlib_LINKFLAGS = ['-Wl,-Bstatic']
+staticlib_PATTERN = 'lib%s.a'
View
30 build/config.log
@@ -0,0 +1,30 @@
+# project configured on Sun Feb 28 13:14:34 2010 by
+# waf 1.5.10 (abi 7, python 20604f0 on linux2)
+# using /usr/local/bin/node-waf configure build
+#
+Checking for program g++,c++
+
+find program=['g++', 'c++'] paths=[] var='CXX' -> '/usr/bin/g++'
+
+Checking for program cpp
+
+find program=['cpp'] paths=[] var='CPP' -> '/usr/bin/cpp'
+
+Checking for program ar
+
+find program=['ar'] paths=[] var='AR' -> '/usr/bin/ar'
+
+Checking for program ranlib
+
+find program=['ranlib'] paths=[] var='RANLIB' -> '/usr/bin/ranlib'
+
+Checking for g++
+
+Checking for program gcc,cc
+
+find program=['gcc', 'cc'] paths=[] var='CC' -> '/usr/bin/gcc'
+
+Checking for gcc
+
+Checking for node prefix
+
View
BIN  build/default/base64.node
Binary file not shown
View
BIN  build/default/base64_1.o
Binary file not shown
View
81 js_base64_for_comparsion.js
@@ -0,0 +1,81 @@
+ 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);
+ }
View
34 test.js
@@ -1,9 +1,35 @@
var base64 = require("./build/default/base64");
+var jsbase64 = require("./js_base64_for_comparsion");
var sys = require("sys");
-var str = base64.encode('wowdsajjfsdakfhsjkdf673e;;;;;23;!!!!!!1@#$%^&*()');
+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');
+
+
+// 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));
-sys.puts(str);
-
-sys.puts(base64.decode(str));
+// 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: '+(c));
+if (c<js) sys.puts('C++ module faster than JS in '+(js/c)+' times');
+else if (c>js) sys.puts('JS module faster than C++ in '+(c/j)+' times');
View
12 test.php
@@ -1,3 +1,13 @@
<?php
-echo(base64_encode('wowdsajjfsdakfhsjkdf673e;;;;;23;!!!!!!1@#$%^&*()'));
+$m1=microtime();
+for($i=0;$i<10000;$i++) {
+ $h=base64_decode(base64_encode('EdPy2H71Q1MjTzkuRxAr1CJWs2ZapZEuaY3XwJL8mpxaTBLWZPkw1yakKLv2r79eHmNQ1m2Cc6PErAkH5FR3Nmd011F09LCas76Z'.$i));
+}
+$m2=microtime();
+
+$m1=explode(' ',$m1);
+$m1=intval($m1[1].substr($m1[0],2,3));
+$m2=explode(' ',$m2);
+$m2=intval($m2[1].substr($m2[0],2,3));
+echo($m2-$m1);
?>
Please sign in to comment.
Something went wrong with that request. Please try again.