$
This commit is contained in:
5
node_modules/smart-buffer/.prettierrc.yaml
generated
vendored
Normal file
5
node_modules/smart-buffer/.prettierrc.yaml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
parser: typescript
|
||||
printWidth: 120
|
||||
tabWidth: 2
|
||||
singleQuote: true
|
||||
trailingComma: none
|
13
node_modules/smart-buffer/.travis.yml
generated
vendored
Normal file
13
node_modules/smart-buffer/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 6
|
||||
- 8
|
||||
- 10
|
||||
- 12
|
||||
- stable
|
||||
|
||||
before_script:
|
||||
- npm install -g typescript
|
||||
- tsc -p ./
|
||||
|
||||
script: "npm run coveralls"
|
20
node_modules/smart-buffer/LICENSE
generated
vendored
Normal file
20
node_modules/smart-buffer/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2017 Josh Glazebrook
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
633
node_modules/smart-buffer/README.md
generated
vendored
Normal file
633
node_modules/smart-buffer/README.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1233
node_modules/smart-buffer/build/smartbuffer.js
generated
vendored
Normal file
1233
node_modules/smart-buffer/build/smartbuffer.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/smart-buffer/build/smartbuffer.js.map
generated
vendored
Normal file
1
node_modules/smart-buffer/build/smartbuffer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
108
node_modules/smart-buffer/build/utils.js
generated
vendored
Normal file
108
node_modules/smart-buffer/build/utils.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const buffer_1 = require("buffer");
|
||||
/**
|
||||
* Error strings
|
||||
*/
|
||||
const ERRORS = {
|
||||
INVALID_ENCODING: 'Invalid encoding provided. Please specify a valid encoding the internal Node.js Buffer supports.',
|
||||
INVALID_SMARTBUFFER_SIZE: 'Invalid size provided. Size must be a valid integer greater than zero.',
|
||||
INVALID_SMARTBUFFER_BUFFER: 'Invalid Buffer provided in SmartBufferOptions.',
|
||||
INVALID_SMARTBUFFER_OBJECT: 'Invalid SmartBufferOptions object supplied to SmartBuffer constructor or factory methods.',
|
||||
INVALID_OFFSET: 'An invalid offset value was provided.',
|
||||
INVALID_OFFSET_NON_NUMBER: 'An invalid offset value was provided. A numeric value is required.',
|
||||
INVALID_LENGTH: 'An invalid length value was provided.',
|
||||
INVALID_LENGTH_NON_NUMBER: 'An invalid length value was provived. A numeric value is required.',
|
||||
INVALID_TARGET_OFFSET: 'Target offset is beyond the bounds of the internal SmartBuffer data.',
|
||||
INVALID_TARGET_LENGTH: 'Specified length value moves cursor beyong the bounds of the internal SmartBuffer data.',
|
||||
INVALID_READ_BEYOND_BOUNDS: 'Attempted to read beyond the bounds of the managed data.',
|
||||
INVALID_WRITE_BEYOND_BOUNDS: 'Attempted to write beyond the bounds of the managed data.'
|
||||
};
|
||||
exports.ERRORS = ERRORS;
|
||||
/**
|
||||
* Checks if a given encoding is a valid Buffer encoding. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { String } encoding The encoding string to check.
|
||||
*/
|
||||
function checkEncoding(encoding) {
|
||||
if (!buffer_1.Buffer.isEncoding(encoding)) {
|
||||
throw new Error(ERRORS.INVALID_ENCODING);
|
||||
}
|
||||
}
|
||||
exports.checkEncoding = checkEncoding;
|
||||
/**
|
||||
* Checks if a given number is a finite integer. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } value The number value to check.
|
||||
*/
|
||||
function isFiniteInteger(value) {
|
||||
return typeof value === 'number' && isFinite(value) && isInteger(value);
|
||||
}
|
||||
exports.isFiniteInteger = isFiniteInteger;
|
||||
/**
|
||||
* Checks if an offset/length value is valid. (Throws an exception if check fails)
|
||||
*
|
||||
* @param value The value to check.
|
||||
* @param offset True if checking an offset, false if checking a length.
|
||||
*/
|
||||
function checkOffsetOrLengthValue(value, offset) {
|
||||
if (typeof value === 'number') {
|
||||
// Check for non finite/non integers
|
||||
if (!isFiniteInteger(value) || value < 0) {
|
||||
throw new Error(offset ? ERRORS.INVALID_OFFSET : ERRORS.INVALID_LENGTH);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error(offset ? ERRORS.INVALID_OFFSET_NON_NUMBER : ERRORS.INVALID_LENGTH_NON_NUMBER);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if a length value is valid. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } length The value to check.
|
||||
*/
|
||||
function checkLengthValue(length) {
|
||||
checkOffsetOrLengthValue(length, false);
|
||||
}
|
||||
exports.checkLengthValue = checkLengthValue;
|
||||
/**
|
||||
* Checks if a offset value is valid. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } offset The value to check.
|
||||
*/
|
||||
function checkOffsetValue(offset) {
|
||||
checkOffsetOrLengthValue(offset, true);
|
||||
}
|
||||
exports.checkOffsetValue = checkOffsetValue;
|
||||
/**
|
||||
* Checks if a target offset value is out of bounds. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } offset The offset value to check.
|
||||
* @param { SmartBuffer } buff The SmartBuffer instance to check against.
|
||||
*/
|
||||
function checkTargetOffset(offset, buff) {
|
||||
if (offset < 0 || offset > buff.length) {
|
||||
throw new Error(ERRORS.INVALID_TARGET_OFFSET);
|
||||
}
|
||||
}
|
||||
exports.checkTargetOffset = checkTargetOffset;
|
||||
/**
|
||||
* Determines whether a given number is a integer.
|
||||
* @param value The number to check.
|
||||
*/
|
||||
function isInteger(value) {
|
||||
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
|
||||
}
|
||||
/**
|
||||
* 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
|
1
node_modules/smart-buffer/build/utils.js.map
generated
vendored
Normal file
1
node_modules/smart-buffer/build/utils.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
70
node_modules/smart-buffer/docs/CHANGELOG.md
generated
vendored
Normal file
70
node_modules/smart-buffer/docs/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
# Change Log
|
||||
## 4.1.0
|
||||
> Released 07/24/2019
|
||||
* Adds int64 support for node v12+
|
||||
* Drops support for node v4
|
||||
|
||||
## 4.0
|
||||
> Released 10/21/2017
|
||||
* Major breaking changes arriving in v4.
|
||||
|
||||
### New Features
|
||||
* Ability to read data from a specific offset. ex: readInt8(5)
|
||||
* Ability to write over data when an offset is given (see breaking changes) ex: writeInt8(5, 0);
|
||||
* Ability to set internal read and write offsets.
|
||||
|
||||
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
* Old constructor patterns have been completely removed. It's now required to use the SmartBuffer.fromXXX() factory constructors. Read more on the v4 docs.
|
||||
* rewind(), skip(), moveTo() have been removed.
|
||||
* Internal private properties are now prefixed with underscores (_).
|
||||
* **All** writeXXX() methods that are given an offset will now **overwrite data** instead of insert
|
||||
* insertXXX() methods have been added for when you want to insert data at a specific offset (this replaces the old behavior of writeXXX() when an offset was provided)
|
||||
|
||||
|
||||
### Other Changes
|
||||
* Standardizd error messaging
|
||||
* Standardized offset/length bounds and sanity checking
|
||||
* General overall cleanup of code.
|
||||
|
||||
## 3.0.3
|
||||
> Released 02/19/2017
|
||||
* Adds missing type definitions for some internal functions.
|
||||
|
||||
## 3.0.2
|
||||
> Released 02/17/2017
|
||||
|
||||
### Bug Fixes
|
||||
* Fixes a bug where using readString with a length of zero resulted in reading the remaining data instead of returning an empty string. (Fixed by Seldszar)
|
||||
|
||||
## 3.0.1
|
||||
> Released 02/15/2017
|
||||
|
||||
### Bug Fixes
|
||||
* Fixes a bug leftover from the TypeScript refactor where .readIntXXX() resulted in .readUIntXXX() being called by mistake.
|
||||
|
||||
## 3.0
|
||||
> Released 02/12/2017
|
||||
|
||||
### Bug Fixes
|
||||
* readUIntXXXX() methods will now throw an exception if they attempt to read beyond the bounds of the valid buffer data available.
|
||||
* **Note** This is technically a breaking change, so version is bumped to 3.x.
|
||||
|
||||
## 2.0
|
||||
> Relased 01/30/2017
|
||||
|
||||
### New Features:
|
||||
|
||||
* Entire package re-written in TypeScript (2.1)
|
||||
* Backwards compatibility is preserved for now
|
||||
* New factory methods for creating SmartBuffer instances
|
||||
* SmartBuffer.fromSize()
|
||||
* SmartBuffer.fromBuffer()
|
||||
* SmartBuffer.fromOptions()
|
||||
* New SmartBufferOptions constructor options
|
||||
* Added additional tests
|
||||
|
||||
### Bug Fixes:
|
||||
* Fixes a bug where reading null terminated strings may result in an exception.
|
367
node_modules/smart-buffer/docs/README_v3.md
generated
vendored
Normal file
367
node_modules/smart-buffer/docs/README_v3.md
generated
vendored
Normal file
@@ -0,0 +1,367 @@
|
||||
smart-buffer [](https://travis-ci.org/JoshGlazebrook/smart-buffer) [](https://coveralls.io/github/JoshGlazebrook/smart-buffer?branch=master)
|
||||
=============
|
||||
|
||||
smart-buffer is a light Buffer wrapper that takes away the need to keep track of what position to read and write data to and from the underlying Buffer. It also adds null terminating string operations and **grows** as you add more data.
|
||||
|
||||

|
||||
|
||||
### What it's useful for:
|
||||
|
||||
I created smart-buffer because I wanted to simplify the process of using Buffer for building and reading network packets to send over a socket. Rather than having to keep track of which position I need to write a UInt16 to after adding a string of variable length, I simply don't have to.
|
||||
|
||||
Key Features:
|
||||
* Proxies all of the Buffer write and read functions.
|
||||
* Keeps track of read and write positions for you.
|
||||
* Grows the internal Buffer as you add data to it.
|
||||
* Useful string operations. (Null terminating strings)
|
||||
* Allows for inserting values at specific points in the internal Buffer.
|
||||
* Built in TypeScript
|
||||
* Type Definitions Provided
|
||||
|
||||
Requirements:
|
||||
* Node v4.0+ is supported at this time. (Versions prior to 2.0 will work on node 0.10)
|
||||
|
||||
|
||||
#### Note:
|
||||
smart-buffer can be used for writing to an underlying buffer as well as reading from it. It however does not function correctly if you're mixing both read and write operations with each other.
|
||||
|
||||
## Breaking Changes with 2.0
|
||||
The latest version (2.0+) is written in TypeScript, and are compiled to ES6 Javascript. This means the earliest Node.js it supports will be 4.x (in strict mode.) If you're using version 6 and above it will work without any issues. From an API standpoint, 2.0 is backwards compatible. The only difference is SmartBuffer is not exported directly as the root module.
|
||||
|
||||
## Breaking Changes with 3.0
|
||||
Starting with 3.0, if any of the readIntXXXX() methods are called and the requested data is larger than the bounds of the internally managed valid buffer data, an exception will now be thrown.
|
||||
|
||||
## Installing:
|
||||
|
||||
`npm install smart-buffer`
|
||||
|
||||
or
|
||||
|
||||
`yarn add smart-buffer`
|
||||
|
||||
Note: The published NPM package includes the built javascript library.
|
||||
If you cloned this repo and wish to build the library manually use:
|
||||
|
||||
`tsc -p ./`
|
||||
|
||||
## Using smart-buffer
|
||||
|
||||
### Example
|
||||
|
||||
Say you were building a packet that had to conform to the following protocol:
|
||||
|
||||
`[PacketType:2][PacketLength:2][Data:XX]`
|
||||
|
||||
To build this packet using the vanilla Buffer class, you would have to count up the length of the data payload beforehand. You would also need to keep track of the current "cursor" position in your Buffer so you write everything in the right places. With smart-buffer you don't have to do either of those things.
|
||||
|
||||
```javascript
|
||||
// 1.x (javascript)
|
||||
var SmartBuffer = require('smart-buffer');
|
||||
|
||||
// 1.x (typescript)
|
||||
import SmartBuffer = require('smart-buffer');
|
||||
|
||||
// 2.x+ (javascript)
|
||||
const SmartBuffer = require('smart-buffer').SmartBuffer;
|
||||
|
||||
// 2.x+ (typescript)
|
||||
import { SmartBuffer, SmartBufferOptions} from 'smart-buffer';
|
||||
|
||||
function createLoginPacket(username, password, age, country) {
|
||||
let packet = new SmartBuffer();
|
||||
packet.writeUInt16LE(0x0060); // Login Packet Type/ID
|
||||
packet.writeStringNT(username);
|
||||
packet.writeStringNT(password);
|
||||
packet.writeUInt8(age);
|
||||
packet.writeStringNT(country);
|
||||
packet.writeUInt16LE(packet.length - 2, 2);
|
||||
|
||||
return packet.toBuffer();
|
||||
}
|
||||
```
|
||||
With the above function, you now can do this:
|
||||
```javascript
|
||||
let login = createLoginPacket("Josh", "secret123", 22, "United States");
|
||||
|
||||
// <Buffer 60 00 1e 00 4a 6f 73 68 00 73 65 63 72 65 74 31 32 33 00 16 55 6e 69 74 65 64 20 53 74 61 74 65 73 00>
|
||||
```
|
||||
Notice that the `[PacketLength:2]` part of the packet was inserted after we had added everything else, and as shown in the Buffer dump above, is in the correct location along with everything else.
|
||||
|
||||
Reading back the packet we created above is just as easy:
|
||||
```javascript
|
||||
|
||||
let reader = SmartBuffer.fromBuffer(login);
|
||||
|
||||
let logininfo = {
|
||||
packetType: reader.readUInt16LE(),
|
||||
packetLength: reader.readUInt16LE(),
|
||||
username: reader.readStringNT(),
|
||||
password: reader.readStringNT(),
|
||||
age: reader.readUInt8(),
|
||||
country: reader.readStringNT()
|
||||
};
|
||||
|
||||
/*
|
||||
{
|
||||
packetType: 96, (0x0060)
|
||||
packetLength: 30,
|
||||
username: 'Josh',
|
||||
password: 'secret123',
|
||||
age: 22,
|
||||
country: 'United States'
|
||||
};
|
||||
*/
|
||||
```
|
||||
|
||||
# Api Reference:
|
||||
|
||||
### Constructing a smart-buffer
|
||||
|
||||
smart-buffer has a few different ways to construct an instance. Starting with version 2.0, the following factory methods are preffered.
|
||||
|
||||
```javascript
|
||||
let SmartBuffer = require('smart-buffer');
|
||||
|
||||
// Creating SmartBuffer from existing Buffer
|
||||
let buff = SmartBuffer.fromBuffer(buffer); // Creates instance from buffer. (Uses default utf8 encoding)
|
||||
let buff = SmartBuffer.fromBuffer(buffer, 'ascii'); // Creates instance from buffer with ascii encoding for Strings.
|
||||
|
||||
// Creating SmartBuffer with specified internal Buffer size.
|
||||
let buff = SmartBuffer.fromSize(1024); // Creates instance with internal Buffer size of 1024.
|
||||
let buff = SmartBuffer.fromSize(1024, 'utf8'); // Creates instance with intenral Buffer size of 1024, and utf8 encoding.
|
||||
|
||||
// Creating SmartBuffer with options object. This one specifies size and encoding.
|
||||
let buff = SmartBuffer.fromOptions({
|
||||
size: 1024,
|
||||
encoding: 'ascii'
|
||||
});
|
||||
|
||||
// Creating SmartBuffer with options object. This one specified an existing Buffer.
|
||||
let buff = SmartBuffer.fromOptions({
|
||||
buff: buffer
|
||||
});
|
||||
|
||||
// Just want a regular SmartBuffer with all default options?
|
||||
let buff = new SmartBuffer();
|
||||
```
|
||||
|
||||
## Backwards Compatibility:
|
||||
|
||||
All constructors used prior to 2.0 still are supported. However it's not recommended to use these.
|
||||
|
||||
```javascript
|
||||
let writer = new SmartBuffer(); // Defaults to utf8, 4096 length internal Buffer.
|
||||
let writer = new SmartBuffer(1024); // Defaults to utf8, 1024 length internal Buffer.
|
||||
let writer = new SmartBuffer('ascii'); // Sets to ascii encoding, 4096 length internal buffer.
|
||||
let writer = new SmartBuffer(1024, 'ascii'); // Sets to ascii encoding, 1024 length internal buffer.
|
||||
```
|
||||
|
||||
## Reading Data
|
||||
|
||||
smart-buffer supports all of the common read functions you will find in the vanilla Buffer class. The only difference is, you do not need to specify which location to start reading from. This is possible because as you read data out of a smart-buffer, it automatically progresses an internal read offset/position to know where to pick up from on the next read.
|
||||
|
||||
## Reading Numeric Values
|
||||
|
||||
When numeric values, you simply need to call the function you want, and the data is returned.
|
||||
|
||||
Supported Operations:
|
||||
* readInt8
|
||||
* readInt16BE
|
||||
* readInt16LE
|
||||
* readInt32BE
|
||||
* readInt32LE
|
||||
* readBigInt64LE
|
||||
* readBigInt64BE
|
||||
* readUInt8
|
||||
* readUInt16BE
|
||||
* readUInt16LE
|
||||
* readUInt32BE
|
||||
* readUInt32LE
|
||||
* readBigUInt64LE
|
||||
* readBigUInt64BE
|
||||
* readFloatBE
|
||||
* readFloatLE
|
||||
* readDoubleBE
|
||||
* readDoubleLE
|
||||
|
||||
```javascript
|
||||
let reader = new SmartBuffer(somebuffer);
|
||||
let num = reader.readInt8();
|
||||
```
|
||||
|
||||
## Reading String Values
|
||||
|
||||
When reading String values, you can either choose to read a null terminated string, or a string of a specified length.
|
||||
|
||||
### SmartBuffer.readStringNT( [encoding] )
|
||||
> `String` **String encoding to use** - Defaults to the encoding set in the constructor.
|
||||
|
||||
returns `String`
|
||||
|
||||
> Note: When readStringNT is called and there is no null character found, smart-buffer will read to the end of the internal Buffer.
|
||||
|
||||
### SmartBuffer.readString( [length] )
|
||||
### SmartBuffer.readString( [encoding] )
|
||||
### SmartBuffer.readString( [length], [encoding] )
|
||||
> `Number` **Length of the string to read**
|
||||
|
||||
> `String` **String encoding to use** - Defaults to the encoding set in the constructor, or utf8.
|
||||
|
||||
returns `String`
|
||||
|
||||
> Note: When readString is called without a specified length, smart-buffer will read to the end of the internal Buffer.
|
||||
|
||||
|
||||
|
||||
## Reading Buffer Values
|
||||
|
||||
### SmartBuffer.readBuffer( length )
|
||||
> `Number` **Length of data to read into a Buffer**
|
||||
|
||||
returns `Buffer`
|
||||
|
||||
> Note: This function uses `slice` to retrieve the Buffer.
|
||||
|
||||
|
||||
### SmartBuffer.readBufferNT()
|
||||
|
||||
returns `Buffer`
|
||||
|
||||
> Note: This reads the next sequence of bytes in the buffer until a null (0x00) value is found. (Null terminated buffer)
|
||||
> Note: This function uses `slice` to retrieve the Buffer.
|
||||
|
||||
|
||||
## Writing Data
|
||||
|
||||
smart-buffer supports all of the common write functions you will find in the vanilla Buffer class. The only difference is, you do not need to specify which location to write to in your Buffer by default. You do however have the option of **inserting** a piece of data into your smart-buffer at a given location.
|
||||
|
||||
|
||||
## Writing Numeric Values
|
||||
|
||||
|
||||
For numeric values, you simply need to call the function you want, and the data is written at the end of the internal Buffer's current write position. You can specify a offset/position to **insert** the given value at, but keep in mind this does not override data at the given position. This feature also does not work properly when inserting a value beyond the current internal length of the smart-buffer (length being the .length property of the smart-buffer instance you're writing to)
|
||||
|
||||
Supported Operations:
|
||||
* writeInt8
|
||||
* writeInt16BE
|
||||
* writeInt16LE
|
||||
* writeInt32BE
|
||||
* writeInt32LE
|
||||
* writeBigInt64BE
|
||||
* writeBigInt64LE
|
||||
* writeUInt8
|
||||
* writeUInt16BE
|
||||
* writeUInt16LE
|
||||
* writeUInt32BE
|
||||
* writeUInt32LE
|
||||
* writeBigUInt64BE
|
||||
* writeBigUInt64LE
|
||||
* writeFloatBE
|
||||
* writeFloatLE
|
||||
* writeDoubleBE
|
||||
* writeDoubleLE
|
||||
|
||||
The following signature is the same for all the above functions:
|
||||
|
||||
### SmartBuffer.writeInt8( value, [offset] )
|
||||
> `Number` **A valid Int8 number**
|
||||
|
||||
> `Number` **The position to insert this value at**
|
||||
|
||||
returns this
|
||||
|
||||
> Note: All write operations return `this` to allow for chaining.
|
||||
|
||||
## Writing String Values
|
||||
|
||||
When reading String values, you can either choose to write a null terminated string, or a non null terminated string.
|
||||
|
||||
### SmartBuffer.writeStringNT( value, [offset], [encoding] )
|
||||
### SmartBuffer.writeStringNT( value, [offset] )
|
||||
### SmartBuffer.writeStringNT( value, [encoding] )
|
||||
> `String` **String value to write**
|
||||
|
||||
> `Number` **The position to insert this String at**
|
||||
|
||||
> `String` **The String encoding to use.** - Defaults to the encoding set in the constructor, or utf8.
|
||||
|
||||
returns this
|
||||
|
||||
### SmartBuffer.writeString( value, [offset], [encoding] )
|
||||
### SmartBuffer.writeString( value, [offset] )
|
||||
### SmartBuffer.writeString( value, [encoding] )
|
||||
> `String` **String value to write**
|
||||
|
||||
> `Number` **The position to insert this String at**
|
||||
|
||||
> `String` **The String encoding to use** - Defaults to the encoding set in the constructor, or utf8.
|
||||
|
||||
returns this
|
||||
|
||||
|
||||
## Writing Buffer Values
|
||||
|
||||
### SmartBuffer.writeBuffer( value, [offset] )
|
||||
> `Buffer` **Buffer value to write**
|
||||
|
||||
> `Number` **The position to insert this Buffer's content at**
|
||||
|
||||
returns this
|
||||
|
||||
### SmartBuffer.writeBufferNT( value, [offset] )
|
||||
> `Buffer` **Buffer value to write**
|
||||
|
||||
> `Number` **The position to insert this Buffer's content at**
|
||||
|
||||
returns this
|
||||
|
||||
|
||||
## Utility Functions
|
||||
|
||||
### SmartBuffer.clear()
|
||||
Resets the SmartBuffer to its default state where it can be reused for reading or writing.
|
||||
|
||||
### SmartBuffer.remaining()
|
||||
|
||||
returns `Number` The amount of data left to read based on the current read Position.
|
||||
|
||||
### SmartBuffer.skip( value )
|
||||
> `Number` **The amount of bytes to skip ahead**
|
||||
|
||||
Skips the read position ahead by the given value.
|
||||
|
||||
returns this
|
||||
|
||||
### SmartBuffer.rewind( value )
|
||||
> `Number` **The amount of bytes to reward backwards**
|
||||
|
||||
Rewinds the read position backwards by the given value.
|
||||
|
||||
returns this
|
||||
|
||||
### SmartBuffer.moveTo( position )
|
||||
> `Number` **The point to skip the read position to**
|
||||
|
||||
Moves the read position to the given point.
|
||||
returns this
|
||||
|
||||
### SmartBuffer.toBuffer()
|
||||
|
||||
returns `Buffer` A Buffer containing the contents of the internal Buffer.
|
||||
|
||||
> Note: This uses the slice function.
|
||||
|
||||
### SmartBuffer.toString( [encoding] )
|
||||
> `String` **The String encoding to use** - Defaults to the encoding set in the constructor, or utf8.
|
||||
|
||||
returns `String` The internal Buffer in String representation.
|
||||
|
||||
## Properties
|
||||
|
||||
### SmartBuffer.length
|
||||
|
||||
returns `Number` **The length of the data that is being tracked in the internal Buffer** - Does NOT return the absolute length of the internal Buffer being written to.
|
||||
|
||||
## License
|
||||
|
||||
This work is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
|
0
node_modules/smart-buffer/docs/ROADMAP.md
generated
vendored
Normal file
0
node_modules/smart-buffer/docs/ROADMAP.md
generated
vendored
Normal file
79
node_modules/smart-buffer/package.json
generated
vendored
Normal file
79
node_modules/smart-buffer/package.json
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"name": "smart-buffer",
|
||||
"version": "4.2.0",
|
||||
"description": "smart-buffer is a Buffer wrapper that adds automatic read & write offset tracking, string operations, data insertions, and more.",
|
||||
"main": "build/smartbuffer.js",
|
||||
"contributors": ["syvita"],
|
||||
"homepage": "https://github.com/JoshGlazebrook/smart-buffer/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/JoshGlazebrook/smart-buffer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/JoshGlazebrook/smart-buffer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"buffer",
|
||||
"smart",
|
||||
"packet",
|
||||
"serialize",
|
||||
"network",
|
||||
"cursor",
|
||||
"simple"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 6.0.0",
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"author": "Josh Glazebrook",
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md",
|
||||
"devDependencies": {
|
||||
"@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": "6.2.0",
|
||||
"mocha-lcov-reporter": "^1.3.0",
|
||||
"nyc": "14.1.1",
|
||||
"source-map-support": "0.5.12",
|
||||
"ts-node": "8.3.0",
|
||||
"tslint": "5.18.0",
|
||||
"typescript": "^3.2.1"
|
||||
},
|
||||
"typings": "typings/smartbuffer.d.ts",
|
||||
"dependencies": {},
|
||||
"scripts": {
|
||||
"prepublish": "npm install -g typescript && npm run build",
|
||||
"test": "NODE_ENV=test mocha --recursive --require ts-node/register test/**/*.ts",
|
||||
"coverage": "NODE_ENV=test nyc npm test",
|
||||
"coveralls": "NODE_ENV=test nyc npm test && nyc report --reporter=text-lcov | coveralls",
|
||||
"lint": "tslint --type-check --project tsconfig.json 'src/**/*.ts'",
|
||||
"build": "tsc -p ./"
|
||||
},
|
||||
"nyc": {
|
||||
"extension": [
|
||||
".ts",
|
||||
".tsx"
|
||||
],
|
||||
"include": [
|
||||
"src/*.ts",
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**.*.d.ts",
|
||||
"node_modules",
|
||||
"typings"
|
||||
],
|
||||
"require": [
|
||||
"ts-node/register"
|
||||
],
|
||||
"reporter": [
|
||||
"json",
|
||||
"html"
|
||||
],
|
||||
"all": true
|
||||
}
|
||||
}
|
755
node_modules/smart-buffer/typings/smartbuffer.d.ts
generated
vendored
Normal file
755
node_modules/smart-buffer/typings/smartbuffer.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
66
node_modules/smart-buffer/typings/utils.d.ts
generated
vendored
Normal file
66
node_modules/smart-buffer/typings/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/// <reference types="node" />
|
||||
import { SmartBuffer } from './smartbuffer';
|
||||
import { Buffer } from 'buffer';
|
||||
/**
|
||||
* Error strings
|
||||
*/
|
||||
declare const ERRORS: {
|
||||
INVALID_ENCODING: string;
|
||||
INVALID_SMARTBUFFER_SIZE: string;
|
||||
INVALID_SMARTBUFFER_BUFFER: string;
|
||||
INVALID_SMARTBUFFER_OBJECT: string;
|
||||
INVALID_OFFSET: string;
|
||||
INVALID_OFFSET_NON_NUMBER: string;
|
||||
INVALID_LENGTH: string;
|
||||
INVALID_LENGTH_NON_NUMBER: string;
|
||||
INVALID_TARGET_OFFSET: string;
|
||||
INVALID_TARGET_LENGTH: string;
|
||||
INVALID_READ_BEYOND_BOUNDS: string;
|
||||
INVALID_WRITE_BEYOND_BOUNDS: string;
|
||||
};
|
||||
/**
|
||||
* Checks if a given encoding is a valid Buffer encoding. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { String } encoding The encoding string to check.
|
||||
*/
|
||||
declare function checkEncoding(encoding: BufferEncoding): void;
|
||||
/**
|
||||
* Checks if a given number is a finite integer. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } value The number value to check.
|
||||
*/
|
||||
declare function isFiniteInteger(value: number): boolean;
|
||||
/**
|
||||
* Checks if a length value is valid. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } length The value to check.
|
||||
*/
|
||||
declare function checkLengthValue(length: any): void;
|
||||
/**
|
||||
* Checks if a offset value is valid. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } offset The value to check.
|
||||
*/
|
||||
declare function checkOffsetValue(offset: any): void;
|
||||
/**
|
||||
* Checks if a target offset value is out of bounds. (Throws an exception if check fails)
|
||||
*
|
||||
* @param { Number } offset The offset value to check.
|
||||
* @param { SmartBuffer } buff The SmartBuffer instance to check against.
|
||||
*/
|
||||
declare function checkTargetOffset(offset: number, buff: SmartBuffer): void;
|
||||
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 };
|
Reference in New Issue
Block a user