bytestreamjs
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,2 +5,3 @@ "use strict"; | ||
const byte_stream_1 = require("./byte_stream"); | ||
const pow2_24 = 16777216; | ||
class SeqStream { | ||
@@ -392,51 +393,36 @@ constructor(parameters = {}) { | ||
return 0; | ||
const value = new Uint16Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
view[0] = block[1]; | ||
view[1] = block[0]; | ||
return value[0]; | ||
return (block[0] << 8) | block[1]; | ||
} | ||
getInt16(changeLength = true) { | ||
const block = this.getBlock(2, changeLength); | ||
if (block.length < 2) | ||
return 0; | ||
const value = new Int16Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
view[0] = block[1]; | ||
view[1] = block[0]; | ||
return value[0]; | ||
const num = this.getUint16(changeLength); | ||
const negative = 0x8000; | ||
if (num & negative) { | ||
return -(negative - (num ^ negative)); | ||
} | ||
return num; | ||
} | ||
getUint24(changeLength = true) { | ||
const block = this.getBlock(3, changeLength); | ||
const block = this.getBlock(4, changeLength); | ||
if (block.length < 3) | ||
return 0; | ||
const value = new Uint32Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
for (let i = 3; i >= 1; i--) { | ||
view[3 - i] = block[i - 1]; | ||
} | ||
return value[0]; | ||
return (block[0] << 16) | | ||
(block[1] << 8) | | ||
block[2]; | ||
} | ||
getUint32(changeLength = true) { | ||
const block = this.getBlock(4, changeLength); | ||
if (block.length < 4) { | ||
if (block.length < 4) | ||
return 0; | ||
} | ||
const value = new Uint32Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
for (let i = 3; i >= 0; i--) { | ||
view[3 - i] = block[i]; | ||
} | ||
return value[0]; | ||
return (block[0] * pow2_24) + | ||
(block[1] << 16) + | ||
(block[2] << 8) + | ||
block[3]; | ||
} | ||
getInt32(changeLength = true) { | ||
const block = this.getBlock(4, changeLength); | ||
if (block.length < 4) | ||
return 0; | ||
const value = new Int32Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
for (let i = 3; i >= 0; i--) { | ||
view[3 - i] = block[i]; | ||
const num = this.getUint32(changeLength); | ||
const negative = 0x80000000; | ||
if (num & negative) { | ||
return -(negative - (num ^ negative)); | ||
} | ||
return value[0]; | ||
return num; | ||
} | ||
@@ -443,0 +429,0 @@ beforeAppend(size) { |
import { ByteStream } from "./byte_stream"; | ||
const pow2_24 = 16777216; | ||
export class SeqStream { | ||
@@ -388,51 +389,36 @@ constructor(parameters = {}) { | ||
return 0; | ||
const value = new Uint16Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
view[0] = block[1]; | ||
view[1] = block[0]; | ||
return value[0]; | ||
return (block[0] << 8) | block[1]; | ||
} | ||
getInt16(changeLength = true) { | ||
const block = this.getBlock(2, changeLength); | ||
if (block.length < 2) | ||
return 0; | ||
const value = new Int16Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
view[0] = block[1]; | ||
view[1] = block[0]; | ||
return value[0]; | ||
const num = this.getUint16(changeLength); | ||
const negative = 0x8000; | ||
if (num & negative) { | ||
return -(negative - (num ^ negative)); | ||
} | ||
return num; | ||
} | ||
getUint24(changeLength = true) { | ||
const block = this.getBlock(3, changeLength); | ||
const block = this.getBlock(4, changeLength); | ||
if (block.length < 3) | ||
return 0; | ||
const value = new Uint32Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
for (let i = 3; i >= 1; i--) { | ||
view[3 - i] = block[i - 1]; | ||
} | ||
return value[0]; | ||
return (block[0] << 16) | | ||
(block[1] << 8) | | ||
block[2]; | ||
} | ||
getUint32(changeLength = true) { | ||
const block = this.getBlock(4, changeLength); | ||
if (block.length < 4) { | ||
if (block.length < 4) | ||
return 0; | ||
} | ||
const value = new Uint32Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
for (let i = 3; i >= 0; i--) { | ||
view[3 - i] = block[i]; | ||
} | ||
return value[0]; | ||
return (block[0] * pow2_24) + | ||
(block[1] << 16) + | ||
(block[2] << 8) + | ||
block[3]; | ||
} | ||
getInt32(changeLength = true) { | ||
const block = this.getBlock(4, changeLength); | ||
if (block.length < 4) | ||
return 0; | ||
const value = new Int32Array(1); | ||
const view = new Uint8Array(value.buffer); | ||
for (let i = 3; i >= 0; i--) { | ||
view[3 - i] = block[i]; | ||
const num = this.getUint32(changeLength); | ||
const negative = 0x80000000; | ||
if (num & negative) { | ||
return -(negative - (num ^ negative)); | ||
} | ||
return value[0]; | ||
return num; | ||
} | ||
@@ -439,0 +425,0 @@ beforeAppend(size) { |
@@ -61,3 +61,3 @@ { | ||
"name": "bytestreamjs", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"module": "./build/mjs/index.js", | ||
@@ -64,0 +64,0 @@ "main": "./build/cjs/index.js", |
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
169984
4346