aboutsummaryrefslogtreecommitdiff
path: root/node_modules/to-arraybuffer
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/to-arraybuffer
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
downloadwallet-core-de98e0b232509d5f40c135d540a70e415272ff85.tar.xz
node_modules
Diffstat (limited to 'node_modules/to-arraybuffer')
-rw-r--r--node_modules/to-arraybuffer/.npmignore4
-rw-r--r--node_modules/to-arraybuffer/.travis.yml3
-rw-r--r--node_modules/to-arraybuffer/.zuul.yml16
-rw-r--r--node_modules/to-arraybuffer/LICENSE24
-rw-r--r--node_modules/to-arraybuffer/README.md27
-rw-r--r--node_modules/to-arraybuffer/index.js27
-rw-r--r--node_modules/to-arraybuffer/package.json34
-rw-r--r--node_modules/to-arraybuffer/test.js57
8 files changed, 192 insertions, 0 deletions
diff --git a/node_modules/to-arraybuffer/.npmignore b/node_modules/to-arraybuffer/.npmignore
new file mode 100644
index 000000000..6c3df58ff
--- /dev/null
+++ b/node_modules/to-arraybuffer/.npmignore
@@ -0,0 +1,4 @@
+.DS_Store
+node_modules
+npm-debug.log
+.zuulrc
diff --git a/node_modules/to-arraybuffer/.travis.yml b/node_modules/to-arraybuffer/.travis.yml
new file mode 100644
index 000000000..3428b14b3
--- /dev/null
+++ b/node_modules/to-arraybuffer/.travis.yml
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - "4.1" \ No newline at end of file
diff --git a/node_modules/to-arraybuffer/.zuul.yml b/node_modules/to-arraybuffer/.zuul.yml
new file mode 100644
index 000000000..7e60601fa
--- /dev/null
+++ b/node_modules/to-arraybuffer/.zuul.yml
@@ -0,0 +1,16 @@
+ui: tape
+browsers:
+ - name: chrome
+ version: 39..latest
+ - name: firefox
+ version: 34..latest
+ - name: safari
+ version: 5..latest
+ - name: ie
+ version: 10..latest
+ - name: opera
+ version: 11..latest
+ - name: iphone
+ version: 5.1..latest
+ - name: android
+ version: 4.0..latest \ No newline at end of file
diff --git a/node_modules/to-arraybuffer/LICENSE b/node_modules/to-arraybuffer/LICENSE
new file mode 100644
index 000000000..1e936dad4
--- /dev/null
+++ b/node_modules/to-arraybuffer/LICENSE
@@ -0,0 +1,24 @@
+The MIT License
+
+Copyright (c) 2016 John Hiesey
+
+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. \ No newline at end of file
diff --git a/node_modules/to-arraybuffer/README.md b/node_modules/to-arraybuffer/README.md
new file mode 100644
index 000000000..6bdef265b
--- /dev/null
+++ b/node_modules/to-arraybuffer/README.md
@@ -0,0 +1,27 @@
+# to-arraybuffer [![Build Status](https://travis-ci.org/jhiesey/to-arraybuffer.svg?branch=master)](https://travis-ci.org/jhiesey/to-arraybuffer)
+
+[![Sauce Test Status](https://saucelabs.com/browser-matrix/to-arraybuffer.svg)](https://saucelabs.com/u/to-arraybuffer)
+
+Convert from a Buffer to an ArrayBuffer as fast as possible.
+
+Note that in some cases the returned ArrayBuffer is backed by the same memory as the original
+Buffer (but in other cases it is a copy), so **modifying the ArrayBuffer is not recommended**.
+
+This module is designed to work both in node.js and in all browsers with ArrayBuffer support
+when using [the Buffer implementation provided by Browserify](https://www.npmjs.com/package/buffer).
+
+## Usage
+
+``` js
+var toArrayBuffer = require('to-arraybuffer')
+
+var buffer = new Buffer(100)
+// Fill the buffer with some data
+
+var ab = toArrayBuffer(buffer)
+// `ab` now contains the same data as `buffer`
+```
+
+## License
+
+MIT \ No newline at end of file
diff --git a/node_modules/to-arraybuffer/index.js b/node_modules/to-arraybuffer/index.js
new file mode 100644
index 000000000..2f69ae0c8
--- /dev/null
+++ b/node_modules/to-arraybuffer/index.js
@@ -0,0 +1,27 @@
+var Buffer = require('buffer').Buffer
+
+module.exports = function (buf) {
+ // If the buffer is backed by a Uint8Array, a faster version will work
+ if (buf instanceof Uint8Array) {
+ // If the buffer isn't a subarray, return the underlying ArrayBuffer
+ if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
+ return buf.buffer
+ } else if (typeof buf.buffer.slice === 'function') {
+ // Otherwise we need to get a proper copy
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)
+ }
+ }
+
+ if (Buffer.isBuffer(buf)) {
+ // This is the slow version that will work with any Buffer
+ // implementation (even in old browsers)
+ var arrayCopy = new Uint8Array(buf.length)
+ var len = buf.length
+ for (var i = 0; i < len; i++) {
+ arrayCopy[i] = buf[i]
+ }
+ return arrayCopy.buffer
+ } else {
+ throw new Error('Argument must be a Buffer')
+ }
+}
diff --git a/node_modules/to-arraybuffer/package.json b/node_modules/to-arraybuffer/package.json
new file mode 100644
index 000000000..fbfe6c0aa
--- /dev/null
+++ b/node_modules/to-arraybuffer/package.json
@@ -0,0 +1,34 @@
+{
+ "name": "to-arraybuffer",
+ "version": "1.0.1",
+ "description": "Get an ArrayBuffer from a Buffer as fast as possible",
+ "main": "index.js",
+ "scripts": {
+ "test": "npm run test-node && ([ -n \"${TRAVIS_PULL_REQUEST}\" -a \"${TRAVIS_PULL_REQUEST}\" != 'false' ] || npm run test-browser)",
+ "test-node": "tape test.js",
+ "test-browser": "zuul --no-coverage -- test.js",
+ "test-browser-local": "zuul --local 8080 --no-coverage -- test.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jhiesey/to-arraybuffer.git"
+ },
+ "keywords": [
+ "buffer",
+ "to",
+ "arraybuffer",
+ "fast",
+ "read",
+ "only"
+ ],
+ "author": "John Hiesey",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/jhiesey/to-arraybuffer/issues"
+ },
+ "homepage": "https://github.com/jhiesey/to-arraybuffer#readme",
+ "devDependencies": {
+ "tape": "^4.4.0",
+ "zuul": "^3.9.0"
+ }
+}
diff --git a/node_modules/to-arraybuffer/test.js b/node_modules/to-arraybuffer/test.js
new file mode 100644
index 000000000..1814ae3ff
--- /dev/null
+++ b/node_modules/to-arraybuffer/test.js
@@ -0,0 +1,57 @@
+var Buffer = require('buffer').Buffer
+var test = require('tape')
+
+var toArrayBuffer = require('.')
+
+function elementsEqual (ab, buffer) {
+ var view = new Uint8Array(ab)
+ for (var i = 0; i < view.length; i++) {
+ if (view[i] !== buffer[i]) {
+ return false
+ }
+ }
+ return true
+}
+
+test('Basic behavior', function (t) {
+ var buf = new Buffer(10)
+ for (var i = 0; i < 10; i++) {
+ buf[i] = i
+ }
+
+ var ab = toArrayBuffer(buf)
+
+ t.equals(ab.byteLength, 10, 'correct length')
+ t.ok(elementsEqual(ab, buf), 'elements equal')
+ t.end()
+})
+
+test('Behavior when input is a subarray 1', function (t) {
+ var origBuf = new Buffer(10)
+ for (var i = 0; i < 10; i++) {
+ origBuf[i] = i
+ }
+ var buf = origBuf.slice(1)
+
+ var ab = toArrayBuffer(buf)
+
+ t.equals(ab.byteLength, 9, 'correct length')
+ t.ok(elementsEqual(ab, buf), 'elements equal')
+ t.notOk(ab === buf.buffer, 'the underlying ArrayBuffer is not returned when incorrect')
+ t.end()
+})
+
+test('Behavior when input is a subarray 2', function (t) {
+ var origBuf = new Buffer(10)
+ for (var i = 0; i < 10; i++) {
+ origBuf[i] = i
+ }
+ var buf = origBuf.slice(0, 9)
+
+ var ab = toArrayBuffer(buf)
+
+ t.equals(ab.byteLength, 9, 'correct length')
+ t.ok(elementsEqual(ab, buf), 'elements equal')
+ t.notOk(ab === buf.buffer, 'the underlying ArrayBuffer is not returned when incorrect')
+ t.end()
+})