bytes~ Buffer

Buffer is a minimal buffer implementation to store and retrieve data

Constructor

new Buffer()

Methods

Bytes() → {Uint8Array}

Bytes returns the byte slice of the buffer.
Returns:
- The byte slice of the buffer.
Type: 
Uint8Array
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
let bytes = b.Bytes();

Hex() → {string}

Hex returns the hex representation of the buffer.
Returns:
- The hex representation of the buffer.
Type: 
string
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
let hex = b.Hex();

Hexdump() → {string}

Hexdump returns the hexdump representation of the buffer.
Returns:
- The hexdump representation of the buffer.
Type: 
string
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
let hexdump = b.Hexdump();

Len() → {number}

Len returns the length of the buffer.
Returns:
- The length of the buffer.
Type: 
number
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
let length = b.Len();

Pack(formatStr, msg) → {Buffer}

Pack uses structs.Pack and packs given data and appends it to the buffer. It packs the data according to the given format.
Parameters:
NameTypeDescription
formatStrstringThe format string to pack the data.
msgstringThe message to pack.
Throws:
- The error encountered during packing.
Type
error
Returns:
- The buffer after packing the data.
Type: 
Buffer
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
b.Pack('format', 'message');

String() → {string}

String returns the string representation of the buffer.
Returns:
- The string representation of the buffer.
Type: 
string
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
let str = b.String();

Write(data) → {Buffer}

Write appends a byte slice to the buffer.
Parameters:
NameTypeDescription
dataUint8ArrayThe byte slice to append to the buffer.
Returns:
- The buffer after appending the byte slice.
Type: 
Buffer
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
b.Write(new Uint8Array([1, 2, 3]));

WriteString(data) → {Buffer}

WriteString appends a string to the buffer.
Parameters:
NameTypeDescription
datastringThe string to append to the buffer.
Returns:
- The buffer after appending the string.
Type: 
Buffer
Example
let m = require('nuclei/bytes');
let b = m.Buffer();
b.WriteString('data');