pax_global_header00006660000000000000000000000064133521210200014477gustar00rootroot0000000000000052 comment=dfd5acaa7b8b6d65d45a8cc376e4f04e0e8c1fa7 buf-compare-2.0.0/000077500000000000000000000000001335212102000136765ustar00rootroot00000000000000buf-compare-2.0.0/.editorconfig000066400000000000000000000003471335212102000163570ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false buf-compare-2.0.0/.gitattributes000066400000000000000000000000141335212102000165640ustar00rootroot00000000000000* text=auto buf-compare-2.0.0/.gitignore000066400000000000000000000000151335212102000156620ustar00rootroot00000000000000node_modules buf-compare-2.0.0/.jshintrc000066400000000000000000000002521335212102000155220ustar00rootroot00000000000000{ "node": true, "esnext": true, "bitwise": true, "curly": true, "immed": true, "newcap": true, "noarg": true, "undef": true, "unused": "vars", "strict": true } buf-compare-2.0.0/.travis.yml000066400000000000000000000001101335212102000157770ustar00rootroot00000000000000sudo: false language: node_js node_js: - 'iojs' - '0.12' - '0.10' buf-compare-2.0.0/index.js000066400000000000000000000006571335212102000153530ustar00rootroot00000000000000'use strict'; module.exports = Buffer.compare || function (a, b) { if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { throw new TypeError('Arguments must be Buffers'); } if (a === b) { return 0; } var x = a.length; var y = b.length; var len = Math.min(x, y); for (var i = 0; i < len; i++) { if (a[i] !== b[i]) { break; } } if (i !== len) { x = a[i]; y = b[i]; } return x < y ? -1 : y < x ? 1 : 0; }; buf-compare-2.0.0/license000066400000000000000000000021371335212102000152460ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) 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. buf-compare-2.0.0/package.json000066400000000000000000000011571335212102000161700ustar00rootroot00000000000000{ "name": "buf-compare", "version": "2.0.0", "description": "Node.js `Buffer.compare()` ponyfill", "license": "MIT", "repository": "sindresorhus/buf-compare", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=0.10.0" }, "scripts": { "test": "ava" }, "files": [ "index.js" ], "keywords": [ "built-in", "core", "ponyfill", "polyfill", "shim", "buffer", "buffers", "compare", "comparison", "sort", "order" ], "devDependencies": { "ava": "*" } } buf-compare-2.0.0/readme.md000066400000000000000000000021101335212102000154470ustar00rootroot00000000000000# Deprecated Just use [`Buffer.compare()`](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_compare_buf1_buf2). It has been available since Node.js 0.12. --- # buf-compare [![Build Status](https://travis-ci.org/sindresorhus/buf-compare.svg?branch=master)](https://travis-ci.org/sindresorhus/buf-compare) > Node.js [`Buffer.compare()`](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_compare_buf1_buf2) [ponyfill](https://ponyfill.com) ## Install ``` $ npm install --save buf-compare ``` ## Usage ```js var bufCompare = require('buf-compare'); bufCompare(new Buffer('a'), new Buffer('a')); //=> 0 bufCompare(new Buffer('a'), new Buffer('b')); //=> -1 ``` ## API See the [`Buffer.compare()` docs](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_compare_buf1_buf2). ## Related - [buffer-equals](https://github.com/sindresorhus/buffer-equals) - Node.js `buffer.equals()` ponyfill - [buf-indexof](https://github.com/sindresorhus/buf-indexof) - Node.js `buffer.indexOf()` ponyfill ## License MIT © [Sindre Sorhus](http://sindresorhus.com) buf-compare-2.0.0/test.js000066400000000000000000000007651335212102000152230ustar00rootroot00000000000000import test from 'ava'; Buffer.compare = undefined; const m = require('./'); test(t => { // https://github.com/iojs/io.js/blob/19ffb5cf1c50e9d91d0a7a35152d20f175a2385d/test/parallel/test-buffer.js#L1127-L1157 const b = new Buffer('a'); const c = new Buffer('c'); const d = new Buffer('aa'); t.is(m(b, c), -1); t.is(m(c, d), 1); t.is(m(d, b), 1); t.is(m(b, d), -1); t.is(m(c, c), 0); t.throws(() => { m(new Buffer(1), 'abc'); }); t.throws(() => { m('abc', new Buffer(1)); }); });