Browse files

updated readme with examples

  • Loading branch information...
1 parent 4d8827c commit 5269d719a34a80628296e3219f9a77690987aaa6 @pkrumins committed Jul 10, 2010
Showing with 36 additions and 5 deletions.
  1. +36 −5 readme.txt
41 readme.txt
@@ -1,6 +1,5 @@
-This is a node.js C++ module that encodes buffers to base64. And compared to
-all other modules, it works. It does not provide decode functionality because
-I don't currently need it.
+This is a node.js C++ module that encodes and decodes to/from base64. Oh, and
+compared to all other modules, it actually works.
It was written by Peteris Krumins (
His blog is at -- good coders code, great reuse.
@@ -12,11 +11,43 @@ To build the module run:
node-waf configure build
This will produce `base64.node` binary module. To use it, make sure the
-module's directory is in NODE_PATH and then just do the usual:
+module's directory is in NODE_PATH.
+The module exports two functions `encode` and `decode`.
+Encodes a buffer to base64, returns encoded ascii string. Unlike all other
+base64, it actually works well with binary data. If you're wondering why it
+takes a buffer as argument, it's because there is no way to pass binary
+strings to C++ code in a sane way.
+Here is a basic example:
+ var sys = require('sys');
var base64_encode = require('base64').encode;
+ var Buffer = require('buffer').Buffer;
+ var buf = new Buffer('hello world');
+ sys.print(base64_encode(buf));
+ /* Output: aGVsbG8gd29ybGQ= */
+Decodes a buffer containing base64 string, or just a base64 string to original
+ var sys = require('sys');
+ var base64_decode = require('base64').decode;
+ sys.print(base64_decode('aGVsbG8gd29ybGQ='));
-Now you can pass base64_encode the buffers to convert to base64.
+ /* Output: hello world */

0 comments on commit 5269d71

Please sign in to comment.