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

varintes

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

varintes - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0-a.0

5

dist/encode-pack.js

@@ -13,5 +13,4 @@ import { encodingLength } from "./encoding-length.js";

numbers.forEach((n) => {
const bytes = encode(n);
result.set(bytes, offset);
offset += bytes.byteLength;
const [_, len] = encode(n, result, offset);
offset += len;
});

@@ -18,0 +17,0 @@ return result;

8

dist/encode.d.ts
/**
* Encode number as varint bytes.
*
* @param num - Number to encode
* @return Uint8Array - `num` encoded as bytes according to varint spec.
* @param num - Number to encode.
* @param out - Uint8Array bytes to write to. If not specified, empty buffer is used.
* @param offset - Offset to use for the `out` buffer.
* @return [Uint8Array, number] - Uint8Array with`num` encoded as bytes according to varint spec, and number of bytes written.
*/
export declare function encode(num: number): Uint8Array;
export declare function encode(num: number, out?: Uint8Array, offset?: number): [Uint8Array, number];

@@ -9,22 +9,23 @@ import { encodingLength } from "./encoding-length.js";

*
* @param num - Number to encode
* @return Uint8Array - `num` encoded as bytes according to varint spec.
* @param num - Number to encode.
* @param out - Uint8Array bytes to write to. If not specified, empty buffer is used.
* @param offset - Offset to use for the `out` buffer.
* @return [Uint8Array, number] - Uint8Array with`num` encoded as bytes according to varint spec, and number of bytes written.
*/
export function encode(num) {
export function encode(num, out = new Uint8Array(encodingLength(num)), offset = 0) {
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
throw new RangeError(`Could not encode ${num} as varint`);
}
const buffer = new Uint8Array(encodingLength(num));
let bytes = 0;
let bytes = offset;
while (num >= INT) {
buffer[bytes++] = (num & 0xff) | MSB;
out[bytes++] = (num & 0xff) | MSB;
num /= 128;
}
while (num & MSBALL) {
buffer[bytes++] = (num & 0xff) | MSB;
out[bytes++] = (num & 0xff) | MSB;
num >>>= 7;
}
buffer[bytes] = num | 0;
return buffer;
out[bytes] = num | 0;
return [out, bytes - offset + 1];
}
//# sourceMappingURL=encode.js.map
{
"name": "varintes",
"version": "1.0.2",
"version": "2.0.0-a.0",
"description": "Unsigned Varint encoding and decoding, exposed as ESModule",

@@ -67,14 +67,13 @@ "keywords": [

},
"scripts": {
"test": "./node_modules/.bin/tsm ./node_modules/uvu/bin.js . .+\\.test\\.ts",
"build": "./node_modules/.bin/tsc --project tsconfig.build.json",
"prepublishOnly": "pnpm run build"
},
"devDependencies": {
"prettier": "^2.7.1",
"tsm": "^2.2.2",
"typescript": "^4.8.3",
"typescript": "^4.8.4",
"uint8arrays": "^3.1.0",
"uvu": "^0.5.6"
},
"scripts": {
"test": "./node_modules/.bin/tsm ./node_modules/uvu/bin.js . .+\\.test\\.ts",
"build": "./node_modules/.bin/tsc --project tsconfig.build.json"
}
}
}

@@ -52,4 +52,9 @@ # Varintes

# To Do
- [ ] Faster encode by loop unrolling
- [ ] Faster decode by loop unrolling
## License
MIT or APACHE-2.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

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