pax_global_header00006660000000000000000000000064127734214770014530gustar00rootroot0000000000000052 comment=a544dc5b98fc257e1fd8f60f5fb18a1fcb6e1c51 buf-compare-1.0.1/000077500000000000000000000000001277342147700137275ustar00rootroot00000000000000buf-compare-1.0.1/.editorconfig000066400000000000000000000003471277342147700164100ustar00rootroot00000000000000root = 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-1.0.1/.gitattributes000066400000000000000000000000141277342147700166150ustar00rootroot00000000000000* text=auto buf-compare-1.0.1/.gitignore000066400000000000000000000000151277342147700157130ustar00rootroot00000000000000node_modules buf-compare-1.0.1/.jshintrc000066400000000000000000000002521277342147700155530ustar00rootroot00000000000000{ "node": true, "esnext": true, "bitwise": true, "curly": true, "immed": true, "newcap": true, "noarg": true, "undef": true, "unused": "vars", "strict": true } buf-compare-1.0.1/.travis.yml000066400000000000000000000001101277342147700160300ustar00rootroot00000000000000sudo: false language: node_js node_js: - 'iojs' - '0.12' - '0.10' buf-compare-1.0.1/index.js000066400000000000000000000006571277342147700154040ustar00rootroot00000000000000'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-1.0.1/license000066400000000000000000000021371277342147700152770ustar00rootroot00000000000000The 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-1.0.1/package.json000066400000000000000000000011571277342147700162210ustar00rootroot00000000000000{ "name": "buf-compare", "version": "1.0.1", "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-1.0.1/readme.md000066400000000000000000000016321277342147700155100ustar00rootroot00000000000000# 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-1.0.1/test.js000066400000000000000000000007651277342147700152540ustar00rootroot00000000000000import 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)); }); });