Socket
Socket
Sign inDemoInstall

bops

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bops - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

11

package.json
{
"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))
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc