Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "bops", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "buffer operations", | ||
@@ -34,3 +34,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"tape": "~1.0.1" | ||
"tape": "~2.0.0" | ||
}, | ||
@@ -44,7 +44,6 @@ "dependencies": { | ||
"browsers": [ | ||
"ie/10..latest", | ||
"chrome/20..latest", | ||
"firefox/15..latest", | ||
"safari/latest", | ||
"firefox/15..nightly", | ||
"chrome/20..canary", | ||
"opera/11.6..latest", | ||
"safari/4..latest", | ||
"iphone/6", | ||
@@ -51,0 +50,0 @@ "ipad/6" |
@@ -9,2 +9,8 @@ # bops | ||
`bops` presents a JavaScript API for working with binary data that will work exactly the same in supported browsers and in node. due to the way that `Buffer` is implemented in node it is impossible to take code written against the `Buffer` API and make it work on top of binary data structures (Array Buffers and Typed Arrays) in the browser. | ||
instead you have to fake the API on top of `Object`, but `Object` isn't designed for holding raw binary data and will be really slow/memory inefficient for many common binary use cases (parsing files, writing files, etc). | ||
use `bops` in place of `Buffer` or `Uint8Array` to make your binary JS code fast + portable. | ||
```javascript | ||
@@ -11,0 +17,0 @@ var binary = require('bops') |
@@ -16,6 +16,6 @@ var test = require('tape') | ||
test('from utf8 works as expected', function(assert) { | ||
var buf = binary.from('ƒello 淾淾淾 hello world 淾淾 yep ƒuu 淾 \ud83d\ude04', 'utf8') | ||
var buf = binary.from('\ud835\udc00 ƒello 淾淾淾 hello world 淾淾 yep ƒuu 淾 \ud83d\ude04', 'utf8') | ||
, expect | ||
expect = [198,146,101,108,108,111,32,230,183,190,230,183,190,230,183,190,32,104,101,108,108,111,32,119,111,114,108,100,32,230,183,190,230,183,190,32,121,101,112,32,198,146,117,117,32,230,183,190,32,0xF0,0x9F,0x98,0x84] | ||
expect = [0xf0, 0x9d, 0x90, 0x80, 0x20, 198,146,101,108,108,111,32,230,183,190,230,183,190,230,183,190,32,104,101,108,108,111,32,119,111,114,108,100,32,230,183,190,230,183,190,32,121,101,112,32,198,146,117,117,32,230,183,190,32,0xF0,0x9F,0x98,0x84] | ||
@@ -30,2 +30,15 @@ assert.equal(buf.length, expect.length) | ||
test('from utf8 works on odd unicode codepoints', function(assert) { | ||
var string = '好' | ||
var expect = [0xe5, 0xa5, 0xbd] | ||
, buf = binary.from(string) | ||
for(var i = 0, len = buf.length; i < len; ++i) { | ||
assert.equal(binary.readUInt8(buf, i), expect[i]) | ||
} | ||
assert.end() | ||
}) | ||
test('from hex works as expected', function(assert) { | ||
@@ -32,0 +45,0 @@ var buf = binary.from('68656c6c6f20776f726c64c692000a0809', 'hex') |
@@ -94,2 +94,3 @@ module.exports = from | ||
if(pos) { | ||
_byte |= +!!(code & 1) << (7 - pos) | ||
arr[arr.length] = _byte | ||
@@ -103,2 +104,3 @@ } | ||
} | ||
return str | ||
@@ -132,6 +134,4 @@ } | ||
function from_base64(str) { | ||
return new Uint8Array(base64.toByteArray(str)) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39789
1147
100