Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Forked from Marak/base64.js
Created September 29, 2011 06:39

Revisions

  1. jhurliman revised this gist Sep 30, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions base64.js
    Original file line number Diff line number Diff line change
    @@ -18,11 +18,11 @@ base64.decode = function(encoded) {

    base64.urlEncode = function(unencoded) {
    var encoded = base64.encode(unencoded);
    return encoded.replace('+', '-').replace('/', '_').replace(/=+$/, '');
    return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
    };

    base64.urlDecode = function(encoded) {
    encoded = encoded.replace('-', '+').replace('_', '/');
    encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
    while (encoded.length % 4)
    encoded += '=';
    return base64.decode(encoded);
  2. jhurliman revised this gist Sep 29, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions base64.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    * base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
    *
    * (C) 2010, Nodejitsu Inc.
    * (C) 2011, Cull TV, Inc.
    *
    */

  3. jhurliman revised this gist Sep 29, 2011. 1 changed file with 15 additions and 3 deletions.
    18 changes: 15 additions & 3 deletions base64.js
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,22 @@

    var base64 = exports;

    base64.encode = function (unencoded) {
    base64.encode = function(unencoded) {
    return new Buffer(unencoded || '').toString('base64');
    };

    base64.decode = function (encoded) {
    base64.decode = function(encoded) {
    return new Buffer(encoded || '', 'base64').toString('utf8');
    };
    };

    base64.urlEncode = function(unencoded) {
    var encoded = base64.encode(unencoded);
    return encoded.replace('+', '-').replace('/', '_').replace(/=+$/, '');
    };

    base64.urlDecode = function(encoded) {
    encoded = encoded.replace('-', '+').replace('_', '/');
    while (encoded.length % 4)
    encoded += '=';
    return base64.decode(encoded);
    };
  4. @Marak Marak created this gist Feb 8, 2011.
    16 changes: 16 additions & 0 deletions base64.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /*
    * base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
    *
    * (C) 2010, Nodejitsu Inc.
    *
    */

    var base64 = exports;

    base64.encode = function (unencoded) {
    return new Buffer(unencoded || '').toString('base64');
    };

    base64.decode = function (encoded) {
    return new Buffer(encoded || '', 'base64').toString('utf8');
    };