Socket
Socket
Sign inDemoInstall

smart-buffer

Package Overview
Dependencies
0
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.2 to 4.1.0

154

build/smartbuffer.js

@@ -148,2 +148,22 @@ "use strict";

/**
* Reads a BigInt64BE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigInt64BE(offset) {
utils_1.bigIntAndBufferInt64Check('readBigInt64BE');
return this._readNumberValue(Buffer.prototype.readBigInt64BE, 8, offset);
}
/**
* Reads a BigInt64LE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigInt64LE(offset) {
utils_1.bigIntAndBufferInt64Check('readBigInt64LE');
return this._readNumberValue(Buffer.prototype.readBigInt64LE, 8, offset);
}
/**
* Writes an Int8 value to the current write position (or at optional offset).

@@ -259,2 +279,50 @@ *

}
/**
* Writes a BigInt64BE value to the current write position (or at optional offset).
*
* @param value { BigInt } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigInt64BE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigInt64BE');
return this._writeNumberValue(Buffer.prototype.writeBigInt64BE, 8, value, offset);
}
/**
* Inserts a BigInt64BE value at the given offset value.
*
* @param value { BigInt } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigInt64BE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigInt64BE');
return this._insertNumberValue(Buffer.prototype.writeBigInt64BE, 8, value, offset);
}
/**
* Writes a BigInt64LE value to the current write position (or at optional offset).
*
* @param value { BigInt } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigInt64LE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigInt64LE');
return this._writeNumberValue(Buffer.prototype.writeBigInt64LE, 8, value, offset);
}
/**
* Inserts a Int64LE value at the given offset value.
*
* @param value { BigInt } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigInt64LE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigInt64LE');
return this._insertNumberValue(Buffer.prototype.writeBigInt64LE, 8, value, offset);
}
// Unsigned Integers

@@ -307,2 +375,22 @@ /**

/**
* Reads a BigUInt64BE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigUInt64BE(offset) {
utils_1.bigIntAndBufferInt64Check('readBigUInt64BE');
return this._readNumberValue(Buffer.prototype.readBigUInt64BE, 8, offset);
}
/**
* Reads a BigUInt64LE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigUInt64LE(offset) {
utils_1.bigIntAndBufferInt64Check('readBigUInt64LE');
return this._readNumberValue(Buffer.prototype.readBigUInt64LE, 8, offset);
}
/**
* Writes an UInt8 value to the current write position (or at optional offset).

@@ -417,2 +505,50 @@ *

}
/**
* Writes a BigUInt64BE value to the current write position (or at optional offset).
*
* @param value { Number } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigUInt64BE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigUInt64BE');
return this._writeNumberValue(Buffer.prototype.writeBigUInt64BE, 8, value, offset);
}
/**
* Inserts a BigUInt64BE value at the given offset value.
*
* @param value { Number } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigUInt64BE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigUInt64BE');
return this._insertNumberValue(Buffer.prototype.writeBigUInt64BE, 8, value, offset);
}
/**
* Writes a BigUInt64LE value to the current write position (or at optional offset).
*
* @param value { Number } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigUInt64LE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigUInt64LE');
return this._writeNumberValue(Buffer.prototype.writeBigUInt64LE, 8, value, offset);
}
/**
* Inserts a BigUInt64LE value at the given offset value.
*
* @param value { Number } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigUInt64LE(value, offset) {
utils_1.bigIntAndBufferInt64Check('writeBigUInt64LE');
return this._insertNumberValue(Buffer.prototype.writeBigUInt64LE, 8, value, offset);
}
// Floating Point

@@ -1022,2 +1158,4 @@ /**

*
* @typeparam T { number | bigint } The type of the value to be read
*
* @param func { Function(offset: number) => number } The function to read data on the internal Buffer with.

@@ -1027,3 +1165,3 @@ * @param byteSize { Number } The number of bytes read.

*
* @param { Number }
* @returns { T } the number value
*/

@@ -1043,7 +1181,10 @@ _readNumberValue(func, byteSize, offset) {

*
* @param func { Function(offset: number, offset?) => number} The function to write data on the internal Buffer with.
* @typeparam T { number | bigint } The type of the value to be written
*
* @param func { Function(offset: T, offset?) => number} The function to write data on the internal Buffer with.
* @param byteSize { Number } The number of bytes written.
* @param value { Number } The number value to write.
* @param value { T } The number value to write.
* @param offset { Number } the offset to write the number at (REQUIRED).
*
* @returns SmartBuffer this buffer
*/

@@ -1064,7 +1205,10 @@ _insertNumberValue(func, byteSize, value, offset) {

*
* @param func { Function(offset: number, offset?) => number} The function to write data on the internal Buffer with.
* @typeparam T { number | bigint } The type of the value to be written
*
* @param func { Function(offset: T, offset?) => number} The function to write data on the internal Buffer with.
* @param byteSize { Number } The number of bytes written.
* @param value { Number } The number value to write.
* @param value { T } The number value to write.
* @param offset { Number } the offset to write the number at (REQUIRED).
*
* @returns SmartBuffer this buffer
*/

@@ -1071,0 +1215,0 @@ _writeNumberValue(func, byteSize, value, offset) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const buffer_1 = require("buffer");
/**

@@ -27,3 +28,3 @@ * Error strings

function checkEncoding(encoding) {
if (!Buffer.isEncoding(encoding)) {
if (!buffer_1.Buffer.isEncoding(encoding)) {
throw new Error(ERRORS.INVALID_ENCODING);

@@ -96,2 +97,14 @@ }

}
/**
* Throws if Node.js version is too low to support bigint
*/
function bigIntAndBufferInt64Check(bufferMethod) {
if (typeof BigInt === 'undefined') {
throw new Error('Platform does not support JS BigInt type.');
}
if (typeof buffer_1.Buffer.prototype[bufferMethod] === 'undefined') {
throw new Error(`Platform does not support Buffer.prototype.${bufferMethod}.`);
}
}
exports.bigIntAndBufferInt64Check = bigIntAndBufferInt64Check;
//# sourceMappingURL=utils.js.map
# Change Log
## 4.1.0
> Released 07/24/2019
* Adds int64 support for node v12+
* Drops support for node v4
## 4.0

@@ -3,0 +8,0 @@ > Released 10/21/2017

@@ -173,2 +173,4 @@ smart-buffer [![Build Status](https://travis-ci.org/JoshGlazebrook/smart-buffer.svg?branch=master)](https://travis-ci.org/JoshGlazebrook/smart-buffer) [![Coverage Status](https://coveralls.io/repos/github/JoshGlazebrook/smart-buffer/badge.svg?branch=master)](https://coveralls.io/github/JoshGlazebrook/smart-buffer?branch=master)

* readInt32LE
* readBigInt64LE
* readBigInt64BE
* readUInt8

@@ -179,2 +181,4 @@ * readUInt16BE

* readUInt32LE
* readBigUInt64LE
* readBigUInt64BE
* readFloatBE

@@ -248,2 +252,4 @@ * readFloatLE

* writeInt32LE
* writeBigInt64BE
* writeBigInt64LE
* writeUInt8

@@ -254,2 +260,4 @@ * writeUInt16BE

* writeUInt32LE
* writeBigUInt64BE
* writeBigUInt64LE
* writeFloatBE

@@ -256,0 +264,0 @@ * writeFloatLE

28

package.json
{
"name": "smart-buffer",
"version": "4.0.2",
"version": "4.1.0",
"description": "smart-buffer is a Buffer wrapper that adds automatic read & write offset tracking, string operations, data insertions, and more.",

@@ -24,3 +24,3 @@ "main": "build/smartbuffer.js",

"engines": {
"node": ">= 4.0.0",
"node": ">= 6.0.0",
"npm": ">= 3.0.0"

@@ -32,15 +32,15 @@ },

"devDependencies": {
"@types/chai": "4.0.4",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.51",
"chai": "4.1.2",
"coveralls": "3.0.0",
"@types/chai": "4.1.7",
"@types/mocha": "5.2.7",
"@types/node": "^12.0.0",
"chai": "4.2.0",
"coveralls": "3.0.5",
"istanbul": "^0.4.5",
"mocha": "4.0.1",
"mocha": "6.2.0",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^11.3.0",
"source-map-support": "0.5.0",
"ts-node": "3.3.0",
"tslint": "5.8.0",
"typescript": "2.6.1"
"nyc": "14.1.1",
"source-map-support": "0.5.12",
"ts-node": "8.3.0",
"tslint": "5.18.0",
"typescript": "^3.2.1"
},

@@ -51,3 +51,3 @@ "typings": "typings/smartbuffer.d.ts",

"prepublish": "npm install -g typescript && npm run build",
"test": "NODE_ENV=test mocha --recursive --compilers ts:ts-node/register test/**/*.ts",
"test": "NODE_ENV=test mocha --recursive --require ts-node/register test/**/*.ts",
"coverage": "NODE_ENV=test nyc npm test",

@@ -54,0 +54,0 @@ "coveralls": "NODE_ENV=test nyc npm test && nyc report --reporter=text-lcov | coveralls",

@@ -86,2 +86,16 @@ /// <reference types="node" />

/**
* Reads a BigInt64BE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigInt64BE(offset?: number): bigint;
/**
* Reads a BigInt64LE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigInt64LE(offset?: number): bigint;
/**
* Writes an Int8 value to the current write position (or at optional offset).

@@ -177,2 +191,38 @@ *

/**
* Writes a BigInt64BE value to the current write position (or at optional offset).
*
* @param value { BigInt } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigInt64BE(value: bigint, offset?: number): SmartBuffer;
/**
* Inserts a BigInt64BE value at the given offset value.
*
* @param value { BigInt } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigInt64BE(value: bigint, offset: number): SmartBuffer;
/**
* Writes a BigInt64LE value to the current write position (or at optional offset).
*
* @param value { BigInt } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigInt64LE(value: bigint, offset?: number): SmartBuffer;
/**
* Inserts a Int64LE value at the given offset value.
*
* @param value { BigInt } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigInt64LE(value: bigint, offset: number): SmartBuffer;
/**
* Reads an UInt8 value from the current read position or an optionally provided offset.

@@ -213,2 +263,16 @@ *

/**
* Reads a BigUInt64BE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigUInt64BE(offset?: number): bigint;
/**
* Reads a BigUInt64LE value from the current read position or an optionally provided offset.
*
* @param offset { Number } The offset to read data from (optional)
* @return { BigInt }
*/
readBigUInt64LE(offset?: number): bigint;
/**
* Writes an UInt8 value to the current write position (or at optional offset).

@@ -304,2 +368,38 @@ *

/**
* Writes a BigUInt64BE value to the current write position (or at optional offset).
*
* @param value { Number } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigUInt64BE(value: bigint, offset?: number): SmartBuffer;
/**
* Inserts a BigUInt64BE value at the given offset value.
*
* @param value { Number } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigUInt64BE(value: bigint, offset: number): SmartBuffer;
/**
* Writes a BigUInt64LE value to the current write position (or at optional offset).
*
* @param value { Number } The value to write.
* @param offset { Number } The offset to write the value at.
*
* @return this
*/
writeBigUInt64LE(value: bigint, offset?: number): SmartBuffer;
/**
* Inserts a BigUInt64LE value at the given offset value.
*
* @param value { Number } The value to insert.
* @param offset { Number } The offset to insert the value at.
*
* @return this
*/
insertBigUInt64LE(value: bigint, offset: number): SmartBuffer;
/**
* Reads an FloatBE value from the current read position or an optionally provided offset.

@@ -528,6 +628,6 @@ *

/**
* Sets the read offset value of the SmartBuffer instance.
*
* @param offset { Number } - The offset value to set.
*/
* Sets the read offset value of the SmartBuffer instance.
*
* @param offset { Number } - The offset value to set.
*/
readOffset: number;

@@ -540,6 +640,6 @@ /**

/**
* Sets the write offset value of the SmartBuffer instance.
*
* @param offset { Number } - The offset value to set.
*/
* Sets the write offset value of the SmartBuffer instance.
*
* @param offset { Number } - The offset value to set.
*/
writeOffset: number;

@@ -552,6 +652,6 @@ /**

/**
* Sets the string encoding of the SmartBuffer instance.
*
* @param encoding { BufferEncoding } The string Buffer encoding to set.
*/
* Sets the string encoding of the SmartBuffer instance.
*
* @param encoding { BufferEncoding } The string Buffer encoding to set.
*/
encoding: BufferEncoding;

@@ -588,3 +688,3 @@ /**

*/
private _handleString(value, isInsert, arg3?, encoding?);
private _handleString;
/**

@@ -596,3 +696,3 @@ * Handles writing or insert of a Buffer.

*/
private _handleBuffer(value, isInsert, offset?);
private _handleBuffer;
/**

@@ -604,3 +704,3 @@ * Ensures that the internal Buffer is large enough to read data.

*/
private ensureReadable(length, offset?);
private ensureReadable;
/**

@@ -612,3 +712,3 @@ * Ensures that the internal Buffer is large enough to insert data.

*/
private ensureInsertable(dataLength, offset);
private ensureInsertable;
/**

@@ -620,3 +720,3 @@ * Ensures that the internal Buffer is large enough to write data.

*/
private _ensureWriteable(dataLength, offset?);
private _ensureWriteable;
/**

@@ -627,6 +727,8 @@ * Ensures that the internal Buffer is large enough to write at least the given amount of data.

*/
private _ensureCapacity(minLength);
private _ensureCapacity;
/**
* Reads a numeric number value using the provided function.
*
* @typeparam T { number | bigint } The type of the value to be read
*
* @param func { Function(offset: number) => number } The function to read data on the internal Buffer with.

@@ -636,26 +738,32 @@ * @param byteSize { Number } The number of bytes read.

*
* @param { Number }
* @returns { T } the number value
*/
private _readNumberValue(func, byteSize, offset?);
private _readNumberValue;
/**
* Inserts a numeric number value based on the given offset and value.
*
* @param func { Function(offset: number, offset?) => number} The function to write data on the internal Buffer with.
* @typeparam T { number | bigint } The type of the value to be written
*
* @param func { Function(offset: T, offset?) => number} The function to write data on the internal Buffer with.
* @param byteSize { Number } The number of bytes written.
* @param value { Number } The number value to write.
* @param value { T } The number value to write.
* @param offset { Number } the offset to write the number at (REQUIRED).
*
* @returns SmartBuffer this buffer
*/
private _insertNumberValue(func, byteSize, value, offset);
private _insertNumberValue;
/**
* Writes a numeric number value based on the given offset and value.
*
* @param func { Function(offset: number, offset?) => number} The function to write data on the internal Buffer with.
* @typeparam T { number | bigint } The type of the value to be written
*
* @param func { Function(offset: T, offset?) => number} The function to write data on the internal Buffer with.
* @param byteSize { Number } The number of bytes written.
* @param value { Number } The number value to write.
* @param value { T } The number value to write.
* @param offset { Number } the offset to write the number at (REQUIRED).
*
* @returns SmartBuffer this buffer
*/
private _writeNumberValue(func, byteSize, value, offset?);
private _writeNumberValue;
}
export { SmartBufferOptions, SmartBuffer };
/// <reference types="node" />
import { SmartBuffer } from './smartbuffer';
import { Buffer } from 'buffer';
/**

@@ -51,2 +52,16 @@ * Error strings

declare function checkTargetOffset(offset: number, buff: SmartBuffer): void;
export { ERRORS, isFiniteInteger, checkEncoding, checkOffsetValue, checkLengthValue, checkTargetOffset };
interface Buffer {
readBigInt64BE(offset?: number): bigint;
readBigInt64LE(offset?: number): bigint;
readBigUInt64BE(offset?: number): bigint;
readBigUInt64LE(offset?: number): bigint;
writeBigInt64BE(value: bigint, offset?: number): number;
writeBigInt64LE(value: bigint, offset?: number): number;
writeBigUInt64BE(value: bigint, offset?: number): number;
writeBigUInt64LE(value: bigint, offset?: number): number;
}
/**
* Throws if Node.js version is too low to support bigint
*/
declare function bigIntAndBufferInt64Check(bufferMethod: keyof Buffer): void;
export { ERRORS, isFiniteInteger, checkEncoding, checkOffsetValue, checkLengthValue, checkTargetOffset, bigIntAndBufferInt64Check };

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc