├── bufferjs ├── index.js ├── package.json ├── add-chunk.js └── indexOf.js ├── examples ├── require-test.js ├── concat-test.js ├── indexOf-test.js └── add-chunk-test.js ├── LICENSE.MIT └── README.md /bufferjs/index.js: -------------------------------------------------------------------------------- 1 | /*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/ 2 | (function () { 3 | "use strict"; 4 | 5 | require('./add-chunk'); 6 | require('./indexOf'); 7 | }()); 8 | -------------------------------------------------------------------------------- /examples/require-test.js: -------------------------------------------------------------------------------- 1 | require('../bufferjs'); 2 | require('../bufferjs/concat'); 3 | require('../bufferjs/add-chunk'); 4 | require('../bufferjs/indexOf'); 5 | 6 | console.log('Buffer.concat:'); 7 | console.log(Buffer.concat); 8 | 9 | console.log('buffer.addChunk:'); 10 | console.log((new Buffer(1).addChunk)); 11 | -------------------------------------------------------------------------------- /examples/concat-test.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | "use strict"; 3 | 4 | require('../bufferjs/concat'); 5 | var assert = require('assert'); 6 | 7 | var abc = new Buffer('abc'), 8 | def = 'def', // Accepts Strings as well 9 | ghi = new Buffer('ghi'), 10 | realResult = abc + def + ghi, 11 | data = Buffer.concat(abc, def, ghi); 12 | 13 | console.log(data.toString()); 14 | assert.equal(abc+def+ghi, data.toString()); 15 | 16 | data = Buffer.concat([abc, def, ghi]); 17 | console.log(data.toString()); 18 | assert.equal(abc+def+ghi, data.toString()); 19 | }()); 20 | -------------------------------------------------------------------------------- /bufferjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "bufferjs", 3 | "description" : "Pure JavaScript Buffer utils.", 4 | "url" : "http://github.com/coolaj86/node-bufferjs/", 5 | "repository" : "coolaj86/node-bufferjs", 6 | "keywords" : ["util", "buffer", "chunk", "indexOf"], 7 | "author" : "AJ ONeal ", 8 | "license" : "MIT", 9 | "contributors" : [ 10 | "Nathan Rajlich ", 11 | "Justin Freitag @justinfreitag" 12 | ], 13 | "dependencies" : {}, 14 | "version" : "3.0.1", 15 | "main" : "./index", 16 | "engines" : { 17 | "node" : ">=0.2.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /bufferjs/add-chunk.js: -------------------------------------------------------------------------------- 1 | /*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/ 2 | (function () { 3 | "use strict"; 4 | 5 | Buffer.prototype.__addchunk_index = 0; 6 | 7 | Buffer.prototype.addChunk = function (chunk) { 8 | var len = Math.min(chunk.length, this.length - this.__addchunk_index); 9 | 10 | if (this.__addchunk_index === this.length) { 11 | //throw new Error("Buffer is full"); 12 | return false; 13 | } 14 | 15 | chunk.copy(this, this.__addchunk_index, 0, len); 16 | 17 | this.__addchunk_index += len; 18 | 19 | if (len < chunk.length) { 20 | //remnant = new Buffer(chunk.length - len); 21 | //chunk.copy(remnant, 0, len, chunk.length); 22 | // return remnant; 23 | return chunk.slice(len, chunk.length); 24 | } 25 | 26 | if (this.__addchunk_index === this.length) { 27 | return true; 28 | } 29 | }; 30 | }()); 31 | -------------------------------------------------------------------------------- /LICENSE.MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 AJ ONeal (and Contributors) 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /bufferjs/indexOf.js: -------------------------------------------------------------------------------- 1 | /*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/ 2 | (function () { 3 | "use strict"; 4 | 5 | /** 6 | * A naiive 'Buffer.indexOf' function. Requires both the 7 | * needle and haystack to be Buffer instances. 8 | */ 9 | function indexOf(haystack, needle, i) { 10 | if (!Buffer.isBuffer(needle)) needle = new Buffer(needle); 11 | if (typeof i === 'undefined') i = 0; 12 | var l = haystack.length - needle.length + 1; 13 | while (i