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.77 to 0.2.78

coverage/tmp/coverage-435985-1685293413916-0.json

2

decoding.d.ts

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

export function readVarString(decoder: Decoder): string;
export function readTerminatedUint8Array(decoder: Decoder): Uint8Array;
export function readTerminatedString(decoder: Decoder): string;
export function peekVarString(decoder: Decoder): string;

@@ -45,0 +47,0 @@ export function readFromDataView(decoder: Decoder, len: number): DataView;

@@ -35,2 +35,3 @@ /**

import * as error from './error.js'
import * as encoding from './encoding.js'

@@ -390,2 +391,27 @@ const errorUnexpectedEndOfArray = error.create('Unexpected end of array')

/**
* @param {Decoder} decoder
* @return {Uint8Array}
*/
export const readTerminatedUint8Array = decoder => {
const encoder = encoding.createEncoder()
let b
while (true) {
b = readUint8(decoder)
if (b === 0) {
return encoding.toUint8Array(encoder)
}
if (b === 1) {
b = readUint8(decoder)
}
encoding.write(encoder, b)
}
}
/**
* @param {Decoder} decoder
* @return {string}
*/
export const readTerminatedString = decoder => string.decodeUtf8(readTerminatedUint8Array(decoder))
/**
* Look ahead and read varString without incrementing position

@@ -392,0 +418,0 @@ *

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

export function readVarString(decoder: Decoder): string;
export function readTerminatedUint8Array(decoder: Decoder): Uint8Array;
export function readTerminatedString(decoder: Decoder): string;
export function peekVarString(decoder: Decoder): string;

@@ -45,0 +47,0 @@ export function readFromDataView(decoder: Decoder, len: number): DataView;

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

export function writeVarString(encoder: Encoder, str: string): void;
export function writeTerminatedString(encoder: Encoder, str: string): void;
export function writeTerminatedUint8Array(encoder: Encoder, buf: Uint8Array): void;
export function writeBinaryEncoder(encoder: Encoder, append: Encoder): void;

@@ -34,0 +36,0 @@ export function writeUint8Array(encoder: Encoder, uint8Array: Uint8Array): void;

@@ -38,2 +38,3 @@ export function testGolangBinaryEncodingCompatibility(): void;

export function testInvalidVarIntEncoding(_tc: t.TestCase): void;
export function testTerminatedEncodering(_tc: t.TestCase): void;
export type EncodingPair = {

@@ -40,0 +41,0 @@ read: (arg0: decoding.Decoder) => any;

@@ -8,2 +8,7 @@ /**

export const fromCodePoint: (...codePoints: number[]) => string;
/**
* The largest utf16 character.
* Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
*/
export const MAX_UTF16_CHARACTER: string;
export function trimLeft(s: string): string;

@@ -10,0 +15,0 @@ export function fromCamelCase(s: string, separator: string): string;

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

export function writeVarString(encoder: Encoder, str: string): void;
export function writeTerminatedString(encoder: Encoder, str: string): void;
export function writeTerminatedUint8Array(encoder: Encoder, buf: Uint8Array): void;
export function writeBinaryEncoder(encoder: Encoder, append: Encoder): void;

@@ -34,0 +36,0 @@ export function writeUint8Array(encoder: Encoder, uint8Array: Uint8Array): void;

@@ -348,2 +348,44 @@ /**

/**
* Write a string terminated by a special byte sequence. This is not very performant and is
* generally discouraged. However, the resulting byte arrays are lexiographically ordered which
* makes this a nice feature for databases.
*
* The string will be encoded using utf8 and then terminated and escaped using writeTerminatingUint8Array.
*
* @function
* @param {Encoder} encoder
* @param {String} str The string that is to be encoded.
*/
export const writeTerminatedString = (encoder, str) =>
writeTerminatedUint8Array(encoder, string.encodeUtf8(str))
/**
* Write a terminating Uint8Array. Note that this is not performant and is generally
* discouraged. There are few situations when this is needed.
*
* We use 0x0 as a terminating character. 0x1 serves as an escape character for 0x0 and 0x1.
*
* Example: [0,1,2] is encoded to [1,0,1,1,2,0]. 0x0, and 0x1 needed to be escaped using 0x1. Then
* the result is terminated using the 0x0 character.
*
* This is basically how many systems implement null terminated strings. However, we use an escape
* character 0x1 to avoid issues and potenial attacks on our database (if this is used as a key
* encoder for NoSql databases).
*
* @function
* @param {Encoder} encoder
* @param {Uint8Array} buf The string that is to be encoded.
*/
export const writeTerminatedUint8Array = (encoder, buf) => {
for (let i = 0; i < buf.length; i++) {
const b = buf[i]
if (b === 0 || b === 1) {
write(encoder, 1)
}
write(encoder, buf[i])
}
write(encoder, 0)
}
/**
* Write the content of another Encoder.

@@ -350,0 +392,0 @@ *

@@ -38,2 +38,3 @@ export function testGolangBinaryEncodingCompatibility(): void;

export function testInvalidVarIntEncoding(_tc: t.TestCase): void;
export function testTerminatedEncodering(_tc: t.TestCase): void;
export type EncodingPair = {

@@ -40,0 +41,0 @@ read: (arg0: decoding.Decoder) => any;

2

package.json
{
"name": "lib0",
"version": "0.2.77",
"version": "0.2.78",
"description": "",

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

@@ -8,2 +8,7 @@ /**

export const fromCodePoint: (...codePoints: number[]) => string;
/**
* The largest utf16 character.
* Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
*/
export const MAX_UTF16_CHARACTER: string;
export function trimLeft(s: string): string;

@@ -10,0 +15,0 @@ export function fromCamelCase(s: string, separator: string): string;

@@ -13,2 +13,8 @@ import * as array from './array.js'

/**
* The largest utf16 character.
* Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
*/
export const MAX_UTF16_CHARACTER = fromCharCode(65535)
/**
* @param {string} s

@@ -15,0 +21,0 @@ * @return {string}

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

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