[Pkg-javascript-commits] [node-base64-arraybuffer] 01/05: Imported Upstream version 0.1.2

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sun Mar 29 18:41:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-base64-arraybuffer.

commit 584c1653597a1107a28b9932bfdcfb909bb0c591
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sun Mar 29 19:36:08 2015 +0200

    Imported Upstream version 0.1.2
---
 .npmignore                      |  1 +
 .travis.yml                     |  6 ++++
 LICENSE-MIT                     | 22 +++++++++++++
 README.md                       | 23 +++++++++++++
 README.md~                      | 23 +++++++++++++
 grunt.js                        | 39 ++++++++++++++++++++++
 lib/base64-arraybuffer.js       | 59 +++++++++++++++++++++++++++++++++
 package.json                    | 35 ++++++++++++++++++++
 package.json~                   | 35 ++++++++++++++++++++
 test/base64-arraybuffer_test.js | 72 +++++++++++++++++++++++++++++++++++++++++
 10 files changed, 315 insertions(+)

diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..2ccbe46
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1 @@
+/node_modules/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..e2eeb99
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,6 @@
+---
+language: node_js
+node_js:
+- '0.10'
+before_script:
+- npm install
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..ed27b41
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Niklas von Hertzen
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b841154
--- /dev/null
+++ b/README.md
@@ -0,0 +1,23 @@
+# base64-arraybuffer
+
+[![Build Status](https://travis-ci.org/niklasvh/base64-arraybuffer.png)](https://travis-ci.org/niklasvh/base64-arraybuffer)
+
+Encode/decode base64 data into ArrayBuffers
+
+## Getting Started
+Install the module with: `npm install base64-arraybuffer`
+
+## API
+The library encodes and decodes base64 to and from ArrayBuffers
+
+ - __encode(buffer)__ - Encodes `ArrayBuffer` into base64 string
+ - __decode(str)__ - Decodes base64 string to `ArrayBuffer`
+
+## Release History
+
+ - 0.1.2 - Fix old format of typed arrays
+ - 0.1.0 - Initial version, basic decode/encode base64 to and from ArrayBuffer
+
+## License
+Copyright (c) 2012 Niklas von Hertzen
+Licensed under the MIT license.
diff --git a/README.md~ b/README.md~
new file mode 100644
index 0000000..b841154
--- /dev/null
+++ b/README.md~
@@ -0,0 +1,23 @@
+# base64-arraybuffer
+
+[![Build Status](https://travis-ci.org/niklasvh/base64-arraybuffer.png)](https://travis-ci.org/niklasvh/base64-arraybuffer)
+
+Encode/decode base64 data into ArrayBuffers
+
+## Getting Started
+Install the module with: `npm install base64-arraybuffer`
+
+## API
+The library encodes and decodes base64 to and from ArrayBuffers
+
+ - __encode(buffer)__ - Encodes `ArrayBuffer` into base64 string
+ - __decode(str)__ - Decodes base64 string to `ArrayBuffer`
+
+## Release History
+
+ - 0.1.2 - Fix old format of typed arrays
+ - 0.1.0 - Initial version, basic decode/encode base64 to and from ArrayBuffer
+
+## License
+Copyright (c) 2012 Niklas von Hertzen
+Licensed under the MIT license.
diff --git a/grunt.js b/grunt.js
new file mode 100644
index 0000000..73c4e7a
--- /dev/null
+++ b/grunt.js
@@ -0,0 +1,39 @@
+module.exports = function(grunt) {
+  "use strict";
+  // Project configuration.
+  grunt.initConfig({
+    pkg: '<json:package.json>',
+    test: {
+      files: ['test/**/*.js']
+    },
+    lint: {
+      files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js']
+    },
+    watch: {
+      files: '<config:lint.files>',
+      tasks: 'default'
+    },
+    jshint: {
+      options: {
+        curly: true,
+        eqeqeq: true,
+        immed: true,
+        latedef: true,
+        newcap: true,
+        noarg: true,
+        sub: true,
+        undef: true,
+        boss: true,
+        eqnull: true,
+        node: true
+      },
+      globals: {
+        exports: true
+      }
+    }
+  });
+
+  // Default task.
+  grunt.registerTask('default', 'test');
+
+};
\ No newline at end of file
diff --git a/lib/base64-arraybuffer.js b/lib/base64-arraybuffer.js
new file mode 100644
index 0000000..362fbfa
--- /dev/null
+++ b/lib/base64-arraybuffer.js
@@ -0,0 +1,59 @@
+/*
+ * base64-arraybuffer
+ * https://github.com/niklasvh/base64-arraybuffer
+ *
+ * Copyright (c) 2012 Niklas von Hertzen
+ * Licensed under the MIT license.
+ */
+(function(chars){
+  "use strict";
+
+  exports.encode = function(arraybuffer) {
+    var bytes = new Uint8Array(arraybuffer),
+    i, len = bytes.length, base64 = "";
+
+    for (i = 0; i < len; i+=3) {
+      base64 += chars[bytes[i] >> 2];
+      base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
+      base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
+      base64 += chars[bytes[i + 2] & 63];
+    }
+
+    if ((len % 3) === 2) {
+      base64 = base64.substring(0, base64.length - 1) + "=";
+    } else if (len % 3 === 1) {
+      base64 = base64.substring(0, base64.length - 2) + "==";
+    }
+
+    return base64;
+  };
+
+  exports.decode =  function(base64) {
+    var bufferLength = base64.length * 0.75,
+    len = base64.length, i, p = 0,
+    encoded1, encoded2, encoded3, encoded4;
+
+    if (base64[base64.length - 1] === "=") {
+      bufferLength--;
+      if (base64[base64.length - 2] === "=") {
+        bufferLength--;
+      }
+    }
+
+    var arraybuffer = new ArrayBuffer(bufferLength),
+    bytes = new Uint8Array(arraybuffer);
+
+    for (i = 0; i < len; i+=4) {
+      encoded1 = chars.indexOf(base64[i]);
+      encoded2 = chars.indexOf(base64[i+1]);
+      encoded3 = chars.indexOf(base64[i+2]);
+      encoded4 = chars.indexOf(base64[i+3]);
+
+      bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
+      bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
+      bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
+    }
+
+    return arraybuffer;
+  };
+})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..15e5347
--- /dev/null
+++ b/package.json
@@ -0,0 +1,35 @@
+{
+  "name": "base64-arraybuffer",
+  "description": "Encode/decode base64 data into ArrayBuffers",
+  "version": "0.1.2",
+  "homepage": "https://github.com/niklasvh/base64-arraybuffer",
+  "author": {
+    "name": "Niklas von Hertzen",
+    "email": "niklasvh at gmail.com",
+    "url": "http://hertzen.com"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/niklasvh/base64-arraybuffer"
+  },
+  "bugs": {
+    "url": "https://github.com/niklasvh/base64-arraybuffer/issues"
+  },
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "https://github.com/niklasvh/base64-arraybuffer/blob/master/LICENSE-MIT"
+    }
+  ],
+  "main": "lib/base64-arraybuffer",
+  "engines": {
+    "node": ">= 0.6.0"
+  },
+  "scripts": {
+    "test": "grunt test"
+  },
+  "devDependencies": {
+    "grunt": "~0.3.17"
+  },
+  "keywords": []
+}
diff --git a/package.json~ b/package.json~
new file mode 100644
index 0000000..251031a
--- /dev/null
+++ b/package.json~
@@ -0,0 +1,35 @@
+{
+  "name": "base64-arraybuffer",
+  "description": "Encode/decode base64 data into ArrayBuffers",
+  "version": "0.1.1",
+  "homepage": "https://github.com/niklasvh/base64-arraybuffer",
+  "author": {
+    "name": "Niklas von Hertzen",
+    "email": "niklasvh at gmail.com",
+    "url": "http://hertzen.com"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/niklasvh/base64-arraybuffer"
+  },
+  "bugs": {
+    "url": "https://github.com/niklasvh/base64-arraybuffer/issues"
+  },
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "https://github.com/niklasvh/base64-arraybuffer/blob/master/LICENSE-MIT"
+    }
+  ],
+  "main": "lib/base64-arraybuffer",
+  "engines": {
+    "node": ">= 0.6.0"
+  },
+  "scripts": {
+    "test": "grunt test"
+  },
+  "devDependencies": {
+    "grunt": "~0.3.17"
+  },
+  "keywords": []
+}
diff --git a/test/base64-arraybuffer_test.js b/test/base64-arraybuffer_test.js
new file mode 100644
index 0000000..fe89c22
--- /dev/null
+++ b/test/base64-arraybuffer_test.js
@@ -0,0 +1,72 @@
+(function(){
+  "use strict";
+  var base64_arraybuffer = require('../lib/base64-arraybuffer.js');
+
+  /*
+  ======== A Handy Little Nodeunit Reference ========
+  https://github.com/caolan/nodeunit
+
+  Test methods:
+    test.expect(numAssertions)
+    test.done()
+  Test assertions:
+    test.ok(value, [message])
+    test.equal(actual, expected, [message])
+    test.notEqual(actual, expected, [message])
+    test.deepEqual(actual, expected, [message])
+    test.notDeepEqual(actual, expected, [message])
+    test.strictEqual(actual, expected, [message])
+    test.notStrictEqual(actual, expected, [message])
+    test.throws(block, [error], [message])
+    test.doesNotThrow(block, [error], [message])
+    test.ifError(value)
+*/
+
+
+  function stringArrayBuffer(str) {
+    var buffer = new ArrayBuffer(str.length);
+    var bytes = new Uint8Array(buffer);
+
+    str.split('').forEach(function(str, i) {
+      bytes[i] = str.charCodeAt(0);
+    });
+
+    return buffer;
+  }
+
+  function testArrayBuffers(buffer1, buffer2) {
+    var len1 = buffer1.byteLength,
+    len2 = buffer2.byteLength;
+    if (len1 !== len2) {
+      console.log(buffer1, buffer2);
+      return false;
+    }
+
+    for (var i = 0; i < len1; i++) {
+      if (buffer1[i] !== buffer1[i]) {
+        console.log(i, buffer1, buffer2);
+        return false;
+      }
+    }
+    return true;
+  }
+
+  exports['base64tests'] = {
+    'encode': function(test) {
+      test.expect(4);
+
+      test.equal(base64_arraybuffer.encode(stringArrayBuffer("Hello world")), "SGVsbG8gd29ybGQ=", 'encode "Hello world"');
+      test.equal(base64_arraybuffer.encode(stringArrayBuffer("Man")), 'TWFu', 'encode "Man"');
+      test.equal(base64_arraybuffer.encode(stringArrayBuffer("Ma")), "TWE=", 'encode "Ma"');
+      test.equal(base64_arraybuffer.encode(stringArrayBuffer("Hello worlds!")), "SGVsbG8gd29ybGRzIQ==", 'encode "Hello worlds!"');
+      test.done();
+    },
+    'decode': function(test) {
+      test.expect(3);
+      test.ok(testArrayBuffers(base64_arraybuffer.decode("TWFu"), stringArrayBuffer("Man")), 'decode "Man"');
+      test.ok(testArrayBuffers(base64_arraybuffer.decode("SGVsbG8gd29ybGQ="), stringArrayBuffer("Hello world")), 'decode "Hello world"');
+      test.ok(testArrayBuffers(base64_arraybuffer.decode("SGVsbG8gd29ybGRzIQ=="), stringArrayBuffer("Hello worlds!")), 'decode "Hello worlds!"');
+      test.done();
+    }
+  };
+})();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-base64-arraybuffer.git



More information about the Pkg-javascript-commits mailing list