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() })
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/javascript/node_modules/to-arraybuffer/test.js | |||||
#1 | 18810 | tjuricek |
First-pass at JavaScript client SDK. JavaScript requires Node with Gulp to "browserfy" the library. It's the easiest way I found to use the swagger-js project; bundle up a wrapping method. There is no JavaScript reference guide. The swagger-js doesn't really document what they do very well, actually. Overall I'm not particularly impressed by swagger-js, it was hard to even figure out what the right method syntax was. We may want to invest time in doing it better. This required setting CORS response headers, which are currently defaulted to a fairly insecure setting. |