brainpicture / node-base64 Goto Github PK
View Code? Open in Web Editor NEWC/C++ base64 lib for node
Home Page: nodejs.ru
C/C++ base64 lib for node
Home Page: nodejs.ru
I've got strange results with JPEG headers, results are differents with php.
In PHP :
php -r 'file_put_contents("/tmp/blah", base64_decode("/9j/"));'
// hd /tmp/blah => 0xff 0xd8 0xff
In node-repl :
require('fs').writeFileSync('/tmp/blah', require('node-base64').decode('/9j/'),'binary');
// hd /tmp/blah => 0xfd 0xfd 0xfd
Does the problem comes from binary data decoding ?
If you try to decode message.base64 in https://gist.github.com/763844 you get slightly wrong output. For example, "Itâ��s ghetto" is part of the decoded string, but it should be "It’s ghetto".
var encoded = require('fs').readFileSync(__dirname + '/message.base64', 'ascii'); console.log(require('base64').decode(encoded));
Try encoding any binary data, produces something different than expected.
The build :
$ make
node-waf configure build && mkdir -p ~/.node_libraries && cp ./build/default/base64.node ~/.node_libraries/base64.node
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for program gcc or cc : /usr/bin/gcc
Checking for gcc : ok
Checking for node path : ok /Users/mlecarme/.node_libraries
Checking for node prefix : ok /usr/local/Cellar/node/0.1.103
'configure' finished successfully (0.140s)
Waf: Entering directory `/private/tmp/node-base64/build'
Waf: Leaving directory `/private/tmp/node-base64/build'
'build' finished successfully (0.042s)
The test :
$ make tests
node ./test.js
module:328
process.dlopen(filename, this.exports);
^
Error: dlopen(/private/tmp/node-base64/build/default/base64.node, 1): Symbol not found: __ZN4node6Buffer20constructor_templateE
Referenced from: /private/tmp/node-base64/build/default/base64.node
Expected in: flat namespace
in /private/tmp/node-base64/build/default/base64.node
at Module._loadObjectSync (module:328:11)
at Module.loadSync (module:304:10)
at loadModule (module:251:12)
at require (module:374:12)
at Object.<anonymous> (/private/tmp/node-base64/test.js:1:76)
at Module._compile (module:426:23)
at Module._loadScriptSync (module:436:8)
at Module.loadSync (module:306:10)
at Object.runMain (module:490:22)
at node.js:254:10
make: *** [tests] Error 11
The other problem in your module is that it's leaking memory in base64_encode_binding
. See, you are doing this:
unsigned char* str=base64_decode((unsigned char*)*data,data.length(),&len);
And then you:
return String::New((const char*)str,len);
But String::New
constructs a new string from char *
, it does not copy the pointer internally.
And before this you do:
result = (unsigned char *)malloc(length+1);
in base64_decode
.
This pointer leaks!
My suggested fix:
Handle<Value>
base64_encode_binding(const Arguments& args)
{
HandleScope scope;
String::Utf8Value data(args[0]->ToString());
int len;
unsigned char* str=base64_encode((unsigned char*)*data,data.length(),&len);
Local<String> ret = String::New((const char*)str,len);
free(str);
return ret;
}
Build failed: -> task failed (err #1):
{task: cxx base64.cc -> base64_1.o}
Possibly b/c i am using node 0.2.6?
node 0.1.103 (nvm) + npm
it seems npm generates an incorrect main.js file for node-base64 (this maybe because this module is compiled), the problem is in the line 5 (/lib/node/.npm/node-base64/0.0.1/main.js)
module.exports = require("./package/build/default/")
it should be:
module.exports = require("./package/build/default/base64")
I reported something similar to isaacs once and he thougth it's a problem in this file:
Bug in base64 package.json. It should read "main":"./build/default/base64"
thanks!
danielz
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.