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

lib0

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lib0 - npm Package Compare versions

Comparing version 0.2.30 to 0.2.31

dist/broadcastchannel-a0da2e3a.cjs

2

buffer.d.ts

@@ -7,2 +7,4 @@ export function createUint8ArrayFromLen(len: number): Uint8Array;

export function copyUint8Array(uint8Array: Uint8Array): Uint8Array;
export function encodeAny(data: any): Uint8Array;
export function decodeAny(buf: Uint8Array): any;
//# sourceMappingURL=buffer.d.ts.map

@@ -9,2 +9,4 @@ /**

import * as env from './environment.js'
import * as encoding from './encoding.js'
import * as decoding from './decoding.js'

@@ -92,1 +94,22 @@ /**

}
/**
* Encode anything as a UInt8Array. It's a pun on typescripts's `any` type.
* See encoding.writeAny for more information.
*
* @param {any} data
* @return {Uint8Array}
*/
export const encodeAny = data => {
const encoder = encoding.createEncoder()
encoding.writeAny(encoder, data)
return encoding.toUint8Array(encoder)
}
/**
* Decode an any-encoded value.
*
* @param {Uint8Array} buf
* @return {any}
*/
export const decodeAny = buf => decoding.readAny(decoding.createDecoder(buf))
export function testRepeatBase64Encoding(tc: t.TestCase): void;
export function testAnyEncoding(tc: t.TestCase): void;
import * as t from "./testing.js";
//# sourceMappingURL=buffer.test.d.ts.map

@@ -115,2 +115,30 @@ /**

}
export class IncUintOptRleDecoder extends Decoder {
/**
* @param {Uint8Array} uint8Array
*/
constructor(uint8Array: Uint8Array);
/**
* @type {number}
*/
s: number;
count: number;
read(): number;
}
export class IntDiffOptRleDecoder extends Decoder {
/**
* @param {Uint8Array} uint8Array
*/
constructor(uint8Array: Uint8Array);
/**
* @type {number}
*/
s: number;
count: number;
diff: number;
/**
* @return {number}
*/
read(): number;
}
export class StringDecoder {

@@ -117,0 +145,0 @@ /**

@@ -542,2 +542,65 @@ /**

export class IncUintOptRleDecoder extends Decoder {
/**
* @param {Uint8Array} uint8Array
*/
constructor (uint8Array) {
super(uint8Array)
/**
* @type {number}
*/
this.s = 0
this.count = 0
}
read () {
if (this.count === 0) {
this.s = readVarInt(this)
// if the sign is negative, we read the count too, otherwise count is 1
const isNegative = math.isNegativeZero(this.s)
this.count = 1
if (isNegative) {
this.s = -this.s
this.count = readVarUint(this) + 2
}
}
this.count--
return /** @type {number} */ (this.s++)
}
}
export class IntDiffOptRleDecoder extends Decoder {
/**
* @param {Uint8Array} uint8Array
*/
constructor (uint8Array) {
super(uint8Array)
/**
* @type {number}
*/
this.s = 0
this.count = 0
this.diff = 0
}
/**
* @return {number}
*/
read () {
if (this.count === 0) {
const diff = readVarInt(this)
// if the first bit is set, we read more data
const hasCount = diff & 1
this.diff = diff >> 1
this.count = 1
if (hasCount) {
this.count = readVarUint(this) + 2
}
}
this.s += this.diff
this.count--
return this.s
}
}
export class StringDecoder {

@@ -544,0 +607,0 @@ /**

@@ -7,2 +7,4 @@ export function createUint8ArrayFromLen(len: number): Uint8Array;

export function copyUint8Array(uint8Array: Uint8Array): Uint8Array;
export function encodeAny(data: any): Uint8Array;
export function decodeAny(buf: Uint8Array): any;
//# sourceMappingURL=buffer.d.ts.map
export function testRepeatBase64Encoding(tc: t.TestCase): void;
export function testAnyEncoding(tc: t.TestCase): void;
import * as t from "./testing.js";
//# sourceMappingURL=buffer.test.d.ts.map

@@ -115,2 +115,30 @@ /**

}
export class IncUintOptRleDecoder extends Decoder {
/**
* @param {Uint8Array} uint8Array
*/
constructor(uint8Array: Uint8Array);
/**
* @type {number}
*/
s: number;
count: number;
read(): number;
}
export class IntDiffOptRleDecoder extends Decoder {
/**
* @param {Uint8Array} uint8Array
*/
constructor(uint8Array: Uint8Array);
/**
* @type {number}
*/
s: number;
count: number;
diff: number;
/**
* @return {number}
*/
read(): number;
}
export class StringDecoder {

@@ -117,0 +145,0 @@ /**

@@ -38,4 +38,13 @@ /**

/**
* T must not be null.
* Now come a few stateful encoder that have their own classes.
*/
/**
* Basic Run Length Encoder - a basic compression implementation.
*
* Encodes [1,1,1,7] to [1,3,7,1] (3 times 1, 1 time 7). This encoder might do more harm than good if there are a lot of values that are not repeated.
*
* It was originally used for image compression. Cool .. article http://csbruce.com/cbm/transactor/pdfs/trans_v7_i06.pdf
*
* @note T must not be null!
*
* @template T

@@ -63,2 +72,7 @@ */

}
/**
* Basic diff decoder using variable length encoding.
*
* Encodes the values [3, 1100, 1101, 1050, 0] to [3, 1097, 1, -51, -1050] using writeVarInt.
*/
export class IntDiffEncoder extends Encoder {

@@ -79,2 +93,9 @@ /**

}
/**
* A combination of IntDiffEncoder and RleEncoder.
*
* Basically first writes the IntDiffEncoder and then counts duplicate diffs using RleEncoding.
*
* Encodes the values [1,1,1,2,3,4,5,6] as [1,1,0,2,1,5] (RLE([1,0,0,1,1,1,1,1]) ⇒ RleIntDiff[1,1,0,2,1,5])
*/
export class RleIntDiffEncoder extends Encoder {

@@ -96,2 +117,10 @@ /**

}
/**
* Optimized Rle encoder that does not suffer from the mentioned problem of the basic Rle encoder.
*
* Internally uses VarInt encoder to write unsigned integers. If the input occurs multiple times, we write
* write it as a negative number. The UintOptRleDecoder then understands that it needs to read a count.
*
* Encodes [1,2,3,3,3] as [1,2,-3,3] (once 1, once 2, three times 3)
*/
export class UintOptRleEncoder {

@@ -110,2 +139,64 @@ encoder: Encoder;

}
/**
* Increasing Uint Optimized RLE Encoder
*
* The RLE encoder counts the number of same occurences of the same value.
* The IncUintOptRle encoder counts if the value increases.
* I.e. 7, 8, 9, 10 will be encoded as [-7, 4]. 1, 3, 5 will be encoded
* as [1, 3, 5].
*/
export class IncUintOptRleEncoder {
encoder: Encoder;
/**
* @type {number}
*/
s: number;
count: number;
/**
* @param {number} v
*/
write(v: number): void;
toUint8Array(): Uint8Array;
}
/**
* A combination of the IntDiffEncoder and the UintOptRleEncoder.
*
* The count approach is similar to the UintDiffOptRleEncoder, but instead of using the negative bitflag, it encodes
* in the LSB whether a count is to be read. Therefore this Encoder only supports 31 bit integers!
*
* Encodes [1, 2, 3, 2] as [3, 1, 6, -1] (more specifically [(1 << 1) | 1, (3 << 0) | 0, -1])
*
* Internally uses variable length encoding. Contrary to normal UintVar encoding, the first byte contains:
* * 1 bit that denotes whether the next value is a count (LSB)
* * 1 bit that denotes whether this value is negative (MSB - 1)
* * 1 bit that denotes whether to continue reading the variable length integer (MSB)
*
* Therefore, only five bits remain to encode diff ranges.
*
* Use this Encoder only when appropriate. In most cases, this is probably a bad idea.
*/
export class IntDiffOptRleEncoder {
encoder: Encoder;
/**
* @type {number}
*/
s: number;
count: number;
diff: number;
/**
* @param {number} v
*/
write(v: number): void;
toUint8Array(): Uint8Array;
}
/**
* Optimized String Encoder.
*
* Encoding many small strings in a simple Encoder is not very efficient. The function call to decode a string takes some time and creates references that must be eventually deleted.
* In practice, when decoding several million small strings, the GC will kick in more and more often to collect orphaned string objects (or maybe there is another reason?).
*
* This string encoder solves the above problem. All strings are concatenated and written as a single string using a single encoding call.
*
* The lengths are encoded using a UintOptRleEncoder.
*/
export class StringEncoder {

@@ -112,0 +203,0 @@ /**

@@ -25,2 +25,4 @@ export function testGolangBinaryEncodingCompatibility(): void;

export function testRleIntDiffEncoder(tc: t.TestCase): void;
export function testIntDiffRleEncoder(tc: t.TestCase): void;
export function testIntEncoders(tc: t.TestCase): void;
export function testIntDiffEncoder(tc: t.TestCase): void;

@@ -27,0 +29,0 @@ export function testStringDecoder(tc: t.TestCase): void;

@@ -38,4 +38,13 @@ /**

/**
* T must not be null.
* Now come a few stateful encoder that have their own classes.
*/
/**
* Basic Run Length Encoder - a basic compression implementation.
*
* Encodes [1,1,1,7] to [1,3,7,1] (3 times 1, 1 time 7). This encoder might do more harm than good if there are a lot of values that are not repeated.
*
* It was originally used for image compression. Cool .. article http://csbruce.com/cbm/transactor/pdfs/trans_v7_i06.pdf
*
* @note T must not be null!
*
* @template T

@@ -63,2 +72,7 @@ */

}
/**
* Basic diff decoder using variable length encoding.
*
* Encodes the values [3, 1100, 1101, 1050, 0] to [3, 1097, 1, -51, -1050] using writeVarInt.
*/
export class IntDiffEncoder extends Encoder {

@@ -79,2 +93,9 @@ /**

}
/**
* A combination of IntDiffEncoder and RleEncoder.
*
* Basically first writes the IntDiffEncoder and then counts duplicate diffs using RleEncoding.
*
* Encodes the values [1,1,1,2,3,4,5,6] as [1,1,0,2,1,5] (RLE([1,0,0,1,1,1,1,1]) ⇒ RleIntDiff[1,1,0,2,1,5])
*/
export class RleIntDiffEncoder extends Encoder {

@@ -96,2 +117,10 @@ /**

}
/**
* Optimized Rle encoder that does not suffer from the mentioned problem of the basic Rle encoder.
*
* Internally uses VarInt encoder to write unsigned integers. If the input occurs multiple times, we write
* write it as a negative number. The UintOptRleDecoder then understands that it needs to read a count.
*
* Encodes [1,2,3,3,3] as [1,2,-3,3] (once 1, once 2, three times 3)
*/
export class UintOptRleEncoder {

@@ -110,2 +139,64 @@ encoder: Encoder;

}
/**
* Increasing Uint Optimized RLE Encoder
*
* The RLE encoder counts the number of same occurences of the same value.
* The IncUintOptRle encoder counts if the value increases.
* I.e. 7, 8, 9, 10 will be encoded as [-7, 4]. 1, 3, 5 will be encoded
* as [1, 3, 5].
*/
export class IncUintOptRleEncoder {
encoder: Encoder;
/**
* @type {number}
*/
s: number;
count: number;
/**
* @param {number} v
*/
write(v: number): void;
toUint8Array(): Uint8Array;
}
/**
* A combination of the IntDiffEncoder and the UintOptRleEncoder.
*
* The count approach is similar to the UintDiffOptRleEncoder, but instead of using the negative bitflag, it encodes
* in the LSB whether a count is to be read. Therefore this Encoder only supports 31 bit integers!
*
* Encodes [1, 2, 3, 2] as [3, 1, 6, -1] (more specifically [(1 << 1) | 1, (3 << 0) | 0, -1])
*
* Internally uses variable length encoding. Contrary to normal UintVar encoding, the first byte contains:
* * 1 bit that denotes whether the next value is a count (LSB)
* * 1 bit that denotes whether this value is negative (MSB - 1)
* * 1 bit that denotes whether to continue reading the variable length integer (MSB)
*
* Therefore, only five bits remain to encode diff ranges.
*
* Use this Encoder only when appropriate. In most cases, this is probably a bad idea.
*/
export class IntDiffOptRleEncoder {
encoder: Encoder;
/**
* @type {number}
*/
s: number;
count: number;
diff: number;
/**
* @param {number} v
*/
write(v: number): void;
toUint8Array(): Uint8Array;
}
/**
* Optimized String Encoder.
*
* Encoding many small strings in a simple Encoder is not very efficient. The function call to decode a string takes some time and creates references that must be eventually deleted.
* In practice, when decoding several million small strings, the GC will kick in more and more often to collect orphaned string objects (or maybe there is another reason?).
*
* This string encoder solves the above problem. All strings are concatenated and written as a single string using a single encoding call.
*
* The lengths are encoded using a UintOptRleEncoder.
*/
export class StringEncoder {

@@ -112,0 +203,0 @@ /**

@@ -494,4 +494,14 @@ /**

/**
* T must not be null.
* Now come a few stateful encoder that have their own classes.
*/
/**
* Basic Run Length Encoder - a basic compression implementation.
*
* Encodes [1,1,1,7] to [1,3,7,1] (3 times 1, 1 time 7). This encoder might do more harm than good if there are a lot of values that are not repeated.
*
* It was originally used for image compression. Cool .. article http://csbruce.com/cbm/transactor/pdfs/trans_v7_i06.pdf
*
* @note T must not be null!
*
* @template T

@@ -536,2 +546,7 @@ */

/**
* Basic diff decoder using variable length encoding.
*
* Encodes the values [3, 1100, 1101, 1050, 0] to [3, 1097, 1, -51, -1050] using writeVarInt.
*/
export class IntDiffEncoder extends Encoder {

@@ -559,2 +574,9 @@ /**

/**
* A combination of IntDiffEncoder and RleEncoder.
*
* Basically first writes the IntDiffEncoder and then counts duplicate diffs using RleEncoding.
*
* Encodes the values [1,1,1,2,3,4,5,6] as [1,1,0,2,1,5] (RLE([1,0,0,1,1,1,1,1]) ⇒ RleIntDiff[1,1,0,2,1,5])
*/
export class RleIntDiffEncoder extends Encoder {

@@ -608,2 +630,10 @@ /**

/**
* Optimized Rle encoder that does not suffer from the mentioned problem of the basic Rle encoder.
*
* Internally uses VarInt encoder to write unsigned integers. If the input occurs multiple times, we write
* write it as a negative number. The UintOptRleDecoder then understands that it needs to read a count.
*
* Encodes [1,2,3,3,3] as [1,2,-3,3] (once 1, once 2, three times 3)
*/
export class UintOptRleEncoder {

@@ -638,2 +668,115 @@ constructor () {

/**
* Increasing Uint Optimized RLE Encoder
*
* The RLE encoder counts the number of same occurences of the same value.
* The IncUintOptRle encoder counts if the value increases.
* I.e. 7, 8, 9, 10 will be encoded as [-7, 4]. 1, 3, 5 will be encoded
* as [1, 3, 5].
*/
export class IncUintOptRleEncoder {
constructor () {
this.encoder = new Encoder()
/**
* @type {number}
*/
this.s = 0
this.count = 0
}
/**
* @param {number} v
*/
write (v) {
if (this.s + this.count === v) {
this.count++
} else {
flushUintOptRleEncoder(this)
this.count = 1
this.s = v
}
}
toUint8Array () {
flushUintOptRleEncoder(this)
return toUint8Array(this.encoder)
}
}
/**
* @param {IntDiffOptRleEncoder} encoder
*/
const flushIntDiffOptRleEncoder = encoder => {
if (encoder.count > 0) {
// 31 bit making up the diff | wether to write the counter
const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)
// flush counter, unless this is the first value (count = 0)
// case 1: just a single value. set first bit to positive
// case 2: write several values. set first bit to negative to indicate that there is a length coming
writeVarInt(encoder.encoder, encodedDiff)
if (encoder.count > 1) {
writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw
}
}
}
/**
* A combination of the IntDiffEncoder and the UintOptRleEncoder.
*
* The count approach is similar to the UintDiffOptRleEncoder, but instead of using the negative bitflag, it encodes
* in the LSB whether a count is to be read. Therefore this Encoder only supports 31 bit integers!
*
* Encodes [1, 2, 3, 2] as [3, 1, 6, -1] (more specifically [(1 << 1) | 1, (3 << 0) | 0, -1])
*
* Internally uses variable length encoding. Contrary to normal UintVar encoding, the first byte contains:
* * 1 bit that denotes whether the next value is a count (LSB)
* * 1 bit that denotes whether this value is negative (MSB - 1)
* * 1 bit that denotes whether to continue reading the variable length integer (MSB)
*
* Therefore, only five bits remain to encode diff ranges.
*
* Use this Encoder only when appropriate. In most cases, this is probably a bad idea.
*/
export class IntDiffOptRleEncoder {
constructor () {
this.encoder = new Encoder()
/**
* @type {number}
*/
this.s = 0
this.count = 0
this.diff = 0
}
/**
* @param {number} v
*/
write (v) {
if (this.diff === v - this.s) {
this.s = v
this.count++
} else {
flushIntDiffOptRleEncoder(this)
this.count = 1
this.diff = v - this.s
this.s = v
}
}
toUint8Array () {
flushIntDiffOptRleEncoder(this)
return toUint8Array(this.encoder)
}
}
/**
* Optimized String Encoder.
*
* Encoding many small strings in a simple Encoder is not very efficient. The function call to decode a string takes some time and creates references that must be eventually deleted.
* In practice, when decoding several million small strings, the GC will kick in more and more often to collect orphaned string objects (or maybe there is another reason?).
*
* This string encoder solves the above problem. All strings are concatenated and written as a single string using a single encoding call.
*
* The lengths are encoded using a UintOptRleEncoder.
*/
export class StringEncoder {

@@ -640,0 +783,0 @@ constructor () {

@@ -25,2 +25,4 @@ export function testGolangBinaryEncodingCompatibility(): void;

export function testRleIntDiffEncoder(tc: t.TestCase): void;
export function testIntDiffRleEncoder(tc: t.TestCase): void;
export function testIntEncoders(tc: t.TestCase): void;
export function testIntDiffEncoder(tc: t.TestCase): void;

@@ -27,0 +29,0 @@ export function testStringDecoder(tc: t.TestCase): void;

2

package.json
{
"name": "lib0",
"version": "0.2.30",
"version": "0.2.31",
"description": "",

@@ -5,0 +5,0 @@ "sideEffects": false,

@@ -99,5 +99,6 @@ /**

export const int31 = (gen, min, max) => {
const _min = min & binary.BITS31
const _max = max & binary.BITS31
return math.floor(gen.next() * (math.min(_max - _min + 1, binary.BITS31) & binary.BITS31) + _min)
// we make sure that this is stored as an Int, not a double.
const _min = min & binary.BITS32
const _max = max & binary.BITS32
return math.floor(gen.next() * (math.min(_max - _min + 1, binary.BITS32) & binary.BITS32) + _min)
}

@@ -104,0 +105,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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