Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit 20eccf0e61aef97311deaab0cac30a58e7bea13d @coolaj86 committed
Showing with 134 additions and 0 deletions.
  1. +24 −0 README.md
  2. +94 −0 index.js
  3. +16 −0 package.json
24 README.md
@@ -0,0 +1,24 @@
+Buffer
+===
+
+The goal is to use `UInt8Array` as a buffer backend that completely follows the Node.JS API.
+
+For now, however, this just aliases `Array` as `Buffer` which works for many use caes.
+
+Current Implementation
+---
+
+ var Buffer;
+ (function () {
+ "use strict";
+
+ function createBuffer() {
+ return Array;
+ }
+
+ if ('undefined' === typeof Buffer) {
+ Buffer = createBuffer();
+ }
+
+ module.exports = Buffer;
+ }());
94 index.js
@@ -0,0 +1,94 @@
+var Buffer;
+(function () {
+ "use strict";
+
+ function createBuffer() {
+ return Array;
+
+ /*
+ function Buffer(sizeOrArrayOrString, encoding) {
+ var size, arr, str;
+
+ if ('number' === typeof sizeOrArrayOrString) {
+ size = sizeOrArrayOrString;
+ } else if ('string' === typeof sizeOrArrayOrString) {
+ // TODO handle encoding
+ str = String(sizeOrArrayOrString);
+ arr = arr.split('');
+ size = arr.length;
+ } else {
+ arr = sizeOrArrayOrString;
+ size = arr.length;
+ }
+
+ this.length = size;
+ }
+
+ Buffer.prototype = new Array();
+ delete Buffer.prototype.push;
+ delete Buffer.prototype.pop;
+ delete Buffer.prototype.shift;
+ delete Buffer.prototype.unshift;
+ delete Buffer.prototype.splice;
+
+ Buffer.isBuffer = function (buf) {
+ return buf instanceof Buffer;
+ };
+
+ // TODO
+ Buffer.byteLength = function (string, encoding) {
+ console.log('[todo] byteLength');
+ encoding = encoding || 'utf8';
+ // return string.length;
+ };
+
+ // TODO
+ Buffer.prototype.write = function (string, offset, encoding) {
+ console.log('[todo] write');
+ };
+
+ Buffer.prototype.toString = function (encoding, start, end) {
+ var res = {}
+ , i
+ ;
+
+ start = start || 0;
+ end = end || this.length - 1;
+ res.length = end + 1;
+
+ if (this.length === res.length) {
+ res = this;
+ } else {
+ i = 0;
+ while (start <= end) {
+ res[i] = this[start];
+ i += 1;
+ start += 1;
+ }
+ }
+
+ return JSON.stringify(res);
+ };
+
+ Buffer.prototype.copy = function (targetBuffer, targetStart, sourceStart, sourceEnd) {
+ targetStart = targetStart || 0;
+ sourceStart = sourceStart || 0;
+ sourceEnd = sourceEnd || targetBuffer.length;
+
+ };
+
+ Buffer.prototype.slice = function (start, end) {
+ end = end || this.length;
+ this.slice(start, end);
+ }
+
+ return Buffer;
+ */
+ }
+
+ if ('undefined' === typeof Buffer) {
+ Buffer = createBuffer();
+ }
+
+ module.exports = Buffer;
+}());
16 package.json
@@ -0,0 +1,16 @@
+{
+ "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
+ "name": "Buffer",
+ "description": "API-compatible Node.JS Buffer for Ender.js (browser)",
+ "version": "0.0.0",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/coolaj86/browser-buffer.git"
+ },
+ "main": "index.js",
+ "engines": {
+ "node": ">= 0.2.0"
+ },
+ "dependencies": {},
+ "devDependencies": {}
+}

0 comments on commit 20eccf0

Please sign in to comment.
Something went wrong with that request. Please try again.