Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

b4a

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

b4a - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

lib/utf16le.js

57

browser.js

@@ -5,2 +5,3 @@ const ascii = require('./lib/ascii')

const utf8 = require('./lib/utf8')
const utf16le = require('./lib/utf16le')

@@ -11,2 +12,4 @@ function codecFor (encoding) {

return ascii
case 'base64':
return base64
case 'hex':

@@ -18,4 +21,7 @@ return hex

return utf8
case 'base64':
return base64
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return utf16le
default:

@@ -225,2 +231,46 @@ throw new Error(`Unknown encoding: ${encoding}`)

function swap (buffer, n, m) {
const i = buffer[n]
buffer[n] = buffer[m]
buffer[m] = i
}
function swap16 (buffer) {
const len = buffer.byteLength
if (len % 2 !== 0) throw new RangeError('Buffer size must be a multiple of 16-bits')
for (let i = 0; i < len; i += 2) swap(buffer, i, i + 1)
return buffer
}
function swap32 (buffer) {
const len = buffer.byteLength
if (len % 4 !== 0) throw new RangeError('Buffer size must be a multiple of 32-bits')
for (let i = 0; i < len; i += 4) {
swap(buffer, i, i + 3)
swap(buffer, i + 1, i + 2)
}
return buffer
}
function swap64 (buffer) {
const len = buffer.byteLength
if (len % 8 !== 0) throw new RangeError('Buffer size must be a multiple of 64-bits')
for (let i = 0; i < len; i += 8) {
swap(buffer, i, i + 7)
swap(buffer, i + 1, i + 6)
swap(buffer, i + 2, i + 5)
swap(buffer, i + 3, i + 4)
}
return buffer
}
function toBuffer (buffer) {

@@ -274,2 +324,5 @@ return buffer

from,
swap16,
swap32,
swap64,
toBuffer,

@@ -276,0 +329,0 @@ toString,

@@ -45,2 +45,14 @@ function isBuffer (value) {

function swap16 (buffer) {
return toBuffer(buffer).swap16()
}
function swap32 (buffer) {
return toBuffer(buffer).swap32()
}
function swap64 (buffer) {
return toBuffer(buffer).swap64()
}
function toBuffer (buffer) {

@@ -71,2 +83,5 @@ if (Buffer.isBuffer(buffer)) return buffer

from,
swap16,
swap32,
swap64,
toBuffer,

@@ -73,0 +88,0 @@ toString,

2

package.json
{
"name": "b4a",
"version": "1.2.0",
"version": "1.3.0",
"description": "Bridging the gap between buffers and typed arrays",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -71,2 +71,14 @@ # Buffer for Array

#### `b4a.swap16()`
See https://nodejs.org/api/buffer.html#bufswap16
#### `b4a.swap32()`
See https://nodejs.org/api/buffer.html#bufswap32
#### `b4a.swap64()`
See https://nodejs.org/api/buffer.html#bufswap64
#### `b4a.toBuffer(buffer)`

@@ -73,0 +85,0 @@

Sorry, the diff of this file is not supported yet

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