Socket
Socket
Sign inDemoInstall

bufio

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bufio - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

tsconfig.json

5

lib/encoding.js

@@ -32,5 +32,10 @@ /*!

const BI = typeof BigInt === 'function' ? BigInt : (function(x) { return 0; });
// @ts-ignore
const BIG_U56_MAX = (BI(1) << BI(56)) - BI(1);
// @ts-ignore
const BIG_U64_MAX = (BI(1) << BI(64)) - BI(1);
// @ts-ignore
const BIG_U128_MAX = (BI(1) << BI(128)) - BI(1);
// @ts-ignore
const BIG_U256_MAX = (BI(1) << BI(256)) - BI(1);

@@ -37,0 +42,0 @@

24

lib/reader.js

@@ -25,2 +25,5 @@ /*!

class BufferReader {
/** @type {Buffer} */
data;
/**

@@ -57,3 +60,3 @@ * Create a buffer reader.

* Get total size of passed-in Buffer.
* @returns {Buffer}
* @returns {Number}
*/

@@ -120,3 +123,3 @@

* and return the data read.
* @param {Bolean?} zeroCopy - Do a fast buffer
* @param {Boolean} [zeroCopy=false] Do a fast buffer
* slice instead of allocating a new buffer (warning:

@@ -886,3 +889,3 @@ * may cause memory leaks if not used with care).

* @param {Number} size
* @param {Bolean?} zeroCopy - Do a fast buffer
* @param {Boolean?} [zeroCopy = false] - Do a fast buffer
* slice instead of allocating a new buffer (warning:

@@ -915,3 +918,3 @@ * may cause memory leaks if not used with care).

* Read a varint number of bytes (will do a fast slice if zero copy).
* @param {Bolean?} zeroCopy - Do a fast buffer
* @param {Boolean} [zeroCopy=false] - Do a fast buffer
* slice instead of allocating a new buffer (warning:

@@ -938,2 +941,3 @@ * may cause memory leaks if not used with care).

const data = this.data.slice(0, this.offset + size);
// @ts-ignore
const br = new this.constructor(data);

@@ -951,3 +955,3 @@

* @param {Number} size
* @param {String} enc - Any buffer-supported encoding.
* @param {BufferEncoding} enc - Any buffer-supported encoding.
* @returns {String}

@@ -974,4 +978,4 @@ */

* Read a 32-byte hash.
* @param {String} enc - `"hex"` or `null`.
* @returns {Hash|Buffer}
* @param {BufferEncoding} enc - `"hex"` or `null`.
* @returns {Buffer|String}
*/

@@ -987,3 +991,3 @@

* Read string of a varint length.
* @param {String} enc - Any buffer-supported encoding.
* @param {BufferEncoding} enc - Any buffer-supported encoding.
* @param {Number?} limit - Size limit.

@@ -1010,3 +1014,3 @@ * @returns {String}

* Read a null-terminated string.
* @param {String} enc - Any buffer-supported encoding.
* @param {BufferEncoding} enc - Any buffer-supported encoding.
* @returns {String}

@@ -1040,3 +1044,3 @@ */

* Create a checksum from the last start position.
* @param {Function} hash
* @param {Function|Object} hash
* @returns {Number} Checksum.

@@ -1043,0 +1047,0 @@ */

@@ -30,3 +30,3 @@ /*!

* @constructor
* @param {Number|Buffer} options
* @param {Number|Buffer} [options]
*/

@@ -54,3 +54,4 @@

* Initialize options.
* @param {Object} options
* @param {Number|Buffer} options
* @returns {StaticWriter}
*/

@@ -168,2 +169,3 @@

* @param {Number} off
* @returns {StaticWriter}
*/

@@ -185,2 +187,3 @@

* Destroy the buffer writer.
* @returns {StaticWriter}
*/

@@ -197,2 +200,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -209,2 +213,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -221,2 +226,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -233,2 +239,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -245,2 +252,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -257,2 +265,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -269,2 +278,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -281,2 +291,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -293,2 +304,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -305,2 +317,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -317,2 +330,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -329,2 +343,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -341,2 +356,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -353,2 +369,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -365,2 +382,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -377,2 +395,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -389,2 +408,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -401,2 +421,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -413,2 +434,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -425,2 +447,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -437,2 +460,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -449,2 +473,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -461,2 +486,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -473,2 +499,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -485,2 +512,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -497,2 +525,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -509,2 +538,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -521,2 +551,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -533,2 +564,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -545,2 +577,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -557,2 +590,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -569,2 +603,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -581,2 +616,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -593,2 +629,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -605,2 +642,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -617,2 +655,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -629,2 +668,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -641,2 +681,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -653,2 +694,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -665,2 +707,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -677,2 +720,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -689,2 +733,3 @@

* @param {BigInt} value
* @returns {StaticWriter}
*/

@@ -701,2 +746,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -713,2 +759,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -725,2 +772,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -737,2 +785,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -749,2 +798,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -760,2 +810,3 @@

* @param {Number} value
* @returns {StaticWriter}
*/

@@ -771,2 +822,3 @@

* @param {Buffer} value
* @returns {StaticWriter}
*/

@@ -786,2 +838,3 @@

* @param {Buffer} value
* @returns {StaticWriter}
*/

@@ -803,2 +856,3 @@

* @param {Number} end
* @returns {StaticWriter}
*/

@@ -821,3 +875,4 @@

* @param {String} value
* @param {String?} enc - Any buffer-supported encoding.
* @param {BufferEncoding} [enc='binary'] - Any buffer-supported encoding.
* @returns {StaticWriter}
*/

@@ -846,3 +901,4 @@

* Write a 32 byte hash.
* @param {Hash} value
* @param {Buffer|String} value
* @returns {StaticWriter}
*/

@@ -868,4 +924,5 @@

* Write a string with a varint length before it.
* @param {String}
* @param {String?} enc - Any buffer-supported encoding.
* @param {String} value
* @param {BufferEncoding} [enc='binary'] - Any buffer-supported encoding.
* @returns {StaticWriter}
*/

@@ -896,4 +953,5 @@

* Write a null-terminated string.
* @param {String|Buffer}
* @param {String?} enc - Any buffer-supported encoding.
* @param {String} value
* @param {BufferEncoding} [enc='binary'] - Any buffer-supported encoding.
* @returns {StaticWriter}
*/

@@ -909,3 +967,4 @@

* Calculate and write a checksum for the data written so far.
* @param {Function} hash
* @param {Function|Object} hash
* @returns {StaticWriter}
*/

@@ -933,2 +992,3 @@

* @param {Number} size
* @returns {StaticWriter}
*/

@@ -955,2 +1015,3 @@

* @param {Number} [value=0x00]
* @returns {StaticWriter}
*/

@@ -957,0 +1018,0 @@

@@ -22,2 +22,7 @@ /*!

/**
* @param {this} obj
* @returns {this}
*/
inject(obj) {

@@ -28,3 +33,8 @@ enforce(obj instanceof this.constructor, 'obj', 'struct');

/**
* @returns {this}
*/
clone() {
// @ts-ignore
const copy = new this.constructor();

@@ -38,2 +48,7 @@ return copy.inject(this);

/**
* @param {*} [extra]
* @returns {Number}
*/
getSize(extra) {

@@ -43,2 +58,8 @@ return -1;

/**
* @param {BufferWriter|StaticWriter} bw
* @param {*} [extra]
* @returns {BufferWriter|StaticWriter}
*/
write(bw, extra) {

@@ -48,2 +69,8 @@ return bw;

/**
* @param {BufferReader} br
* @param {*} [extra]
* @returns {this}
*/
read(br, extra) {

@@ -53,2 +80,6 @@ return this;

/**
* @returns {String}
*/
toString() {

@@ -58,2 +89,8 @@ return Object.prototype.toString.call(this);

/**
* @param {String} str
* @param {*} [extra]
* @returns {this}
*/
fromString(str, extra) {

@@ -63,2 +100,6 @@ return this;

/**
* @returns {Object}
*/
getJSON() {

@@ -68,2 +109,8 @@ return this;

/**
* @param {Object} json
* @param {*} [extra]
* @returns {this}
*/
fromJSON(json, extra) {

@@ -73,2 +120,8 @@ return this;

/**
* @param {Object} options
* @param {*} [extra]
* @returns {this}
*/
fromOptions(options, extra) {

@@ -78,2 +131,8 @@ return this;

/**
* @param {Object} options
* @param {*} [extra]
* @returns {this}
*/
from(options, extra) {

@@ -83,2 +142,6 @@ return this.fromOptions(options, extra);

/**
* @returns {*}
*/
format() {

@@ -92,2 +155,7 @@ return this.getJSON();

/**
* @param {*} [extra]
* @returns {Buffer}
*/
encode(extra) {

@@ -104,2 +172,8 @@ const size = this.getSize(extra);

/**
* @param {Buffer} data
* @param {*} [extra]
* @returns {this}
*/
decode(data, extra) {

@@ -113,2 +187,7 @@ const br = new BufferReader(data);

/**
* @param {*} [extra]
* @returns {String}
*/
toHex(extra) {

@@ -118,2 +197,8 @@ return this.encode(extra).toString('hex');

/**
* @param {String} str
* @param {*} [extra]
* @returns {this}
*/
fromHex(str, extra) {

@@ -131,2 +216,7 @@ enforce(typeof str === 'string', 'str', 'string');

/**
* @param {*} [extra]
* @returns {String}
*/
toBase64(extra) {

@@ -136,2 +226,8 @@ return this.encode(extra).toString('base64');

/**
* @param {String} str
* @param {*} [extra]
* @returns {this}
*/
fromBase64(str, extra) {

@@ -148,2 +244,6 @@ enforce(typeof str === 'string', 'str', 'string');

/**
* @returns {Object}
*/
toJSON() {

@@ -197,2 +297,8 @@ return this.getJSON();

/**
* @param {BufferWriter|StaticWriter} bw
* @param {*} [extra]
* @returns {BufferWriter|StaticWriter}
*/
toWriter(bw, extra) {

@@ -202,2 +308,8 @@ return this.write(bw, extra);

/**
* @param {BufferReader} br
* @param {*} [extra]
* @returns {this}
*/
fromReader(br, extra) {

@@ -207,2 +319,7 @@ return this.read(br, extra);

/**
* @param {*} [extra]
* @returns {Buffer}
*/
toRaw(extra) {

@@ -212,2 +329,8 @@ return this.encode(extra);

/**
* @param {Buffer} data
* @param {*} [extra]
* @returns {this}
*/
fromRaw(data, extra) {

@@ -214,0 +337,0 @@ return this.decode(data, extra);

@@ -310,3 +310,4 @@ /*!

* Seek to relative offset.
* @param {Number} offset
* @param {Number} off
* @returns {BufferWriter}
*/

@@ -328,2 +329,3 @@

* Destroy the buffer writer. Remove references to `ops`.
* @returns {BufferWriter}
*/

@@ -340,2 +342,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -352,2 +355,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -364,2 +368,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -376,2 +381,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -388,2 +394,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -400,2 +407,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -412,2 +420,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -424,2 +433,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -436,2 +446,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -448,2 +459,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -460,2 +472,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -472,2 +485,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -484,2 +498,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -496,2 +511,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -508,2 +524,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -520,2 +537,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -532,2 +550,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -544,2 +563,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -556,2 +576,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -568,2 +589,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -580,2 +602,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -592,2 +615,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -604,2 +628,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -616,2 +641,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -628,2 +654,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -640,2 +667,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -652,2 +680,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -664,2 +693,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -676,2 +706,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -688,2 +719,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -700,2 +732,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -712,2 +745,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -724,2 +758,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -736,2 +771,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -748,2 +784,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -760,2 +797,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -772,2 +810,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -784,2 +823,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -796,2 +836,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -808,2 +849,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -820,2 +862,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -832,2 +875,3 @@

* @param {BigInt} value
* @returns {BufferWriter}
*/

@@ -844,2 +888,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -856,2 +901,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -868,2 +914,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -880,2 +927,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -892,2 +940,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -904,2 +953,3 @@

* @param {Number} value
* @returns {BufferWriter}
*/

@@ -916,2 +966,3 @@

* @param {Buffer} value
* @returns {BufferWriter}
*/

@@ -934,2 +985,3 @@

* @param {Buffer} value
* @returns {BufferWriter}
*/

@@ -957,2 +1009,3 @@

* @param {Number} end
* @returns {BufferWriter}
*/

@@ -976,3 +1029,4 @@

* @param {String} value
* @param {String?} enc - Any buffer-supported encoding.
* @param {BufferEncoding} [enc='binary'] - Any buffer-supported encoding.
* @returns {BufferWriter}
*/

@@ -998,3 +1052,4 @@

* Write a 32 byte hash.
* @param {Hash} value
* @param {Buffer|String} value
* @returns {BufferWriter}
*/

@@ -1019,4 +1074,5 @@

* Write a string with a varint length before it.
* @param {String}
* @param {String?} enc - Any buffer-supported encoding.
* @param {String} value
* @param {BufferEncoding} [enc='binary'] - Any buffer-supported encoding.
* @returns {BufferWriter}
*/

@@ -1049,4 +1105,5 @@

* Write a null-terminated string.
* @param {String|Buffer}
* @param {String?} enc - Any buffer-supported encoding.
* @param {String} value
* @param {BufferEncoding} [enc='binary'] - Any buffer-supported encoding.
* @returns {BufferWriter}
*/

@@ -1062,8 +1119,10 @@

* Calculate and write a checksum for the data written so far.
* @param {Function} hash
* @param {Function|Object} hash
* @returns {BufferWriter}
*/
writeChecksum(hash) {
if (hash && typeof hash.digest === 'function')
if (hash && typeof hash.digest === 'function') {
hash = hash.digest.bind(hash);
}

@@ -1082,2 +1141,3 @@ enforce(typeof hash === 'function', 'hash', 'function');

* @param {Number} size
* @returns {BufferWriter}
*/

@@ -1102,2 +1162,3 @@

* @param {Number} [value=0x00]
* @returns {BufferWriter}
*/

@@ -1115,2 +1176,6 @@

class WriteOp {
/**
* @param {Number} type
*/
constructor(type) {

@@ -1117,0 +1182,0 @@ this.type = type;

{
"name": "bufio",
"version": "1.2.0",
"version": "1.2.1",
"description": "Buffer and serialization utilities for javascript",

@@ -18,10 +18,12 @@ "keywords": [

"scripts": {
"lint": "eslint lib/ test/ || exit 0",
"lint": "eslint lib/ test/",
"lint-types": "tsc -p .",
"test": "bmocha --reporter spec test/*-test.js"
},
"devDependencies": {
"bmocha": "^2.1.0"
"bmocha": "^2.1.0",
"bts-type-deps": "^0.0.3"
},
"engines": {
"node": ">=8.0.0"
"node": ">=14.0.0"
},

@@ -28,0 +30,0 @@ "browser": {

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