delete ^& ignore lib

This commit is contained in:
Holly Stubbs 2023-05-12 14:41:35 +01:00
parent c4fe450546
commit b1596e1c45
21 changed files with 135 additions and 666 deletions

3
.gitignore vendored
View file

@ -1,3 +1,6 @@
# Build folder
lib/
# Logs # Logs
logs logs
*.log *.log

130
.npmignore Normal file
View file

@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

9
lib/index.d.ts vendored
View file

@ -1,9 +0,0 @@
/// <reference types="node" />
import { IReader } from "./readers/IReader";
import { IWriter } from "./writers/IWriter";
export declare enum Endian {
LE = 0,
BE = 1
}
export declare function createReader(endianness: Endian, buffer: Buffer): IReader;
export declare function createWriter(endianness: Endian, size?: number): IWriter;

View file

@ -1,30 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWriter = exports.createReader = exports.Endian = void 0;
const ReaderBE_1 = require("./readers/ReaderBE");
const ReaderLE_1 = require("./readers/ReaderLE");
const WriterBE_1 = require("./writers/WriterBE");
const WriterLE_1 = require("./writers/WriterLE");
var Endian;
(function (Endian) {
Endian[Endian["LE"] = 0] = "LE";
Endian[Endian["BE"] = 1] = "BE";
})(Endian = exports.Endian || (exports.Endian = {}));
function createReader(endianness, buffer) {
if (endianness === Endian.LE) {
return new ReaderLE_1.ReaderLE(buffer);
}
else {
return new ReaderBE_1.ReaderBE(buffer);
}
}
exports.createReader = createReader;
function createWriter(endianness, size) {
if (endianness === Endian.LE) {
return new WriterLE_1.WriterLE(size);
}
else {
return new WriterBE_1.WriterBE(size);
}
}
exports.createWriter = createWriter;

View file

@ -1,19 +0,0 @@
/// <reference types="node" />
export interface IReader {
readBuffer(bytes: number): Buffer;
readUint8Array(bytes: number): Uint8Array;
readByte(): number;
readUByte(): number;
readBool(): boolean;
readShort(): number;
readUShort(): number;
readInt(): number;
readUInt(): number;
readLong(): bigint;
readULong(): bigint;
readFloat(): number;
readDouble(): number;
readShortString(): string;
readString(): string;
readString16(): string;
}

View file

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -1,15 +0,0 @@
import { IReader } from "./IReader";
import { ReaderBase } from "./ReaderBase";
export declare class ReaderBE extends ReaderBase implements IReader {
readShort(): number;
readUShort(): number;
readInt(): number;
readUInt(): number;
readLong(): bigint;
readULong(): bigint;
readFloat(): number;
readDouble(): number;
readShortString(): string;
readString(): string;
readString16(): string;
}

View file

@ -1,71 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReaderBE = void 0;
const ReaderBase_1 = require("./ReaderBase");
class ReaderBE extends ReaderBase_1.ReaderBase {
readShort() {
const value = this.buffer.readInt16BE(this.offset);
this.offset += 2;
return value;
}
readUShort() {
const value = this.buffer.readUInt16BE(this.offset);
this.offset += 2;
return value;
}
readInt() {
const value = this.buffer.readInt32BE(this.offset);
this.offset += 4;
return value;
}
readUInt() {
const value = this.buffer.readUInt32BE(this.offset);
this.offset += 4;
return value;
}
readLong() {
const value = this.buffer.readBigInt64BE(this.offset);
this.offset += 8;
return value;
}
readULong() {
const value = this.buffer.readBigUint64BE(this.offset);
this.offset += 8;
return value;
}
readFloat() {
const value = this.buffer.readFloatBE(this.offset);
this.offset += 4;
return value;
}
readDouble() {
const value = this.buffer.readDoubleBE(this.offset);
this.offset += 8;
return value;
}
readShortString() {
const length = this.readUByte();
let text = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUByte());
}
return text;
}
readString() {
const length = this.readUShort();
let text = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUByte());
}
return text;
}
readString16() {
const length = this.readUShort();
let text = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUShort());
}
return text;
}
}
exports.ReaderBE = ReaderBE;

View file

@ -1,11 +0,0 @@
/// <reference types="node" />
export declare class ReaderBase {
buffer: Buffer;
offset: number;
constructor(buffer: Buffer);
readBuffer(bytes: number): Buffer;
readUint8Array(bytes: number): Uint8Array;
readByte(): number;
readUByte(): number;
readBool(): boolean;
}

View file

@ -1,38 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReaderBase = void 0;
class ReaderBase {
constructor(buffer) {
this.buffer = buffer;
this.offset = 0;
}
readBuffer(bytes) {
const value = this.buffer.subarray(this.offset, this.offset + bytes);
this.offset += bytes;
return value;
}
// NOTE: This has to be a copy as the subarray is only cropped & offset
// Realistically this is what we want anyway.
readUint8Array(bytes) {
const croppedBuffer = this.readBuffer(bytes);
const newArray = new Uint8Array(croppedBuffer.length);
for (let i = 0; i < croppedBuffer.length; i++) {
newArray[i] = croppedBuffer[i];
}
return newArray;
}
readByte() {
const value = this.buffer.readInt8(this.offset);
this.offset++;
return value;
}
readUByte() {
const value = this.buffer.readUInt8(this.offset);
this.offset++;
return value;
}
readBool() {
return Boolean(this.readUByte());
}
}
exports.ReaderBase = ReaderBase;

View file

@ -1,15 +0,0 @@
import { IReader } from "./IReader";
import { ReaderBase } from "./ReaderBase";
export declare class ReaderLE extends ReaderBase implements IReader {
readShort(): number;
readUShort(): number;
readInt(): number;
readUInt(): number;
readLong(): bigint;
readULong(): bigint;
readFloat(): number;
readDouble(): number;
readShortString(): string;
readString(): string;
readString16(): string;
}

View file

@ -1,71 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReaderLE = void 0;
const ReaderBase_1 = require("./ReaderBase");
class ReaderLE extends ReaderBase_1.ReaderBase {
readShort() {
const value = this.buffer.readInt16LE(this.offset);
this.offset += 2;
return value;
}
readUShort() {
const value = this.buffer.readUInt16LE(this.offset);
this.offset += 2;
return value;
}
readInt() {
const value = this.buffer.readInt32LE(this.offset);
this.offset += 4;
return value;
}
readUInt() {
const value = this.buffer.readUInt32LE(this.offset);
this.offset += 4;
return value;
}
readLong() {
const value = this.buffer.readBigInt64LE(this.offset);
this.offset += 8;
return value;
}
readULong() {
const value = this.buffer.readBigUint64LE(this.offset);
this.offset += 8;
return value;
}
readFloat() {
const value = this.buffer.readFloatLE(this.offset);
this.offset += 4;
return value;
}
readDouble() {
const value = this.buffer.readDoubleLE(this.offset);
this.offset += 8;
return value;
}
readShortString() {
const length = this.readUByte();
let text = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUByte());
}
return text;
}
readString() {
const length = this.readUShort();
let text = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUByte());
}
return text;
}
readString16() {
const length = this.readUShort();
let text = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUShort());
}
return text;
}
}
exports.ReaderLE = ReaderLE;

View file

@ -1,21 +0,0 @@
/// <reference types="node" />
export interface IWriter {
toBuffer(): Buffer;
toString(): string;
writeBuffer(buffer: Buffer): IWriter;
writeUint8Array(array: Uint8Array): IWriter;
writeByte(value: number): IWriter;
writeUByte(value: number): IWriter;
writeBool(value: boolean | number): IWriter;
writeShort(value: number): IWriter;
writeUShort(value: number): IWriter;
writeInt(value: number): IWriter;
writeUInt(value: number): IWriter;
writeLong(value: number | bigint): IWriter;
writeULong(value: number): IWriter;
writeFloat(value: number): IWriter;
writeDouble(value: number): IWriter;
writeShortString(text: string): IWriter;
writeString(text: string): IWriter;
writeString16(text: string): IWriter;
}

View file

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -1,15 +0,0 @@
import { IWriter } from "./IWriter";
import { WriterBase } from "./WriterBase";
export declare class WriterBE extends WriterBase implements IWriter {
writeShort(value: number): this;
writeUShort(value: number): this;
writeInt(value: number): this;
writeUInt(value: number): this;
writeLong(value: number | bigint): this;
writeULong(value: number | bigint): this;
writeFloat(value: number): this;
writeDouble(value: number): this;
writeShortString(text: string): this;
writeString(text: string): this;
writeString16(text: string): this;
}

View file

@ -1,130 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WriterBE = void 0;
const WriterBase_1 = require("./WriterBase");
class WriterBE extends WriterBase_1.WriterBase {
writeShort(value) {
if (this.resizable) {
const buffer = Buffer.alloc(2);
buffer.writeInt16BE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeInt16BE(value, this.offset);
this.offset += 2;
}
return this;
}
writeUShort(value) {
if (this.resizable) {
const buffer = Buffer.alloc(2);
buffer.writeUInt16BE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeUInt16BE(value, this.offset);
this.offset += 2;
}
return this;
}
writeInt(value) {
if (this.resizable) {
const buffer = Buffer.alloc(4);
buffer.writeInt32BE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeInt32BE(value, this.offset);
this.offset += 4;
}
return this;
}
writeUInt(value) {
if (this.resizable) {
const buffer = Buffer.alloc(4);
buffer.writeUInt32BE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeUInt32BE(value, this.offset);
this.offset += 4;
}
return this;
}
writeLong(value) {
if (typeof (value) !== "bigint") {
value = BigInt(value);
}
if (this.resizable) {
const buffer = Buffer.alloc(8);
buffer.writeBigInt64BE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeBigInt64BE(value, this.offset);
this.offset += 8;
}
return this;
}
writeULong(value) {
if (typeof (value) !== "bigint") {
value = BigInt(value);
}
if (this.resizable) {
const buffer = Buffer.alloc(8);
buffer.writeBigUint64BE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeBigUint64BE(value, this.offset);
this.offset += 8;
}
return this;
}
writeFloat(value) {
if (this.resizable) {
const buffer = Buffer.alloc(4);
buffer.writeFloatBE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeFloatBE(value, this.offset);
this.offset += 4;
}
return this;
}
writeDouble(value) {
if (this.resizable) {
const buffer = Buffer.alloc(8);
buffer.writeDoubleBE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeDoubleBE(value, this.offset);
this.offset += 8;
}
return this;
}
writeShortString(text) {
this.writeUByte(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUByte(text.charCodeAt(i));
}
return this;
}
writeString(text) {
this.writeUShort(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUByte(text.charCodeAt(i));
}
return this;
}
writeString16(text) {
this.writeUShort(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUShort(text.charCodeAt(i));
}
return this;
}
}
exports.WriterBE = WriterBE;

View file

@ -1,14 +0,0 @@
/// <reference types="node" />
export declare class WriterBase {
buffer: Buffer;
offset: number;
readonly resizable: boolean;
constructor(size?: number);
toBuffer(): Buffer;
toString(): string;
writeBuffer(buffer: Buffer): this;
writeUint8Array(array: Uint8Array): this;
writeByte(value: number): this;
writeUByte(value: number): this;
writeBool(value: boolean | number): this;
}

View file

@ -1,56 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WriterBase = void 0;
class WriterBase {
constructor(size = 0) {
this.buffer = Buffer.alloc(size);
this.offset = 0;
this.resizable = size === 0;
}
toBuffer() {
return this.buffer;
}
toString() {
return this.buffer.toString();
}
writeBuffer(buffer) {
this.buffer = Buffer.concat([this.buffer, buffer], this.buffer.length + buffer.length);
return this;
}
writeUint8Array(array) {
this.writeBuffer(Buffer.from(array));
return this;
}
writeByte(value) {
if (this.resizable) {
const buffer = Buffer.alloc(1);
buffer.writeInt8(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeInt8(value, this.offset);
this.offset++;
}
return this;
}
writeUByte(value) {
if (this.resizable) {
const buffer = Buffer.alloc(1);
buffer.writeUInt8(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeUInt8(value, this.offset);
this.offset++;
}
return this;
}
writeBool(value) {
if (typeof (value) === "number") {
value = Boolean(value);
}
this.writeUByte(value ? 1 : 0);
return this;
}
}
exports.WriterBase = WriterBase;

View file

@ -1,15 +0,0 @@
import { IWriter } from "./IWriter";
import { WriterBase } from "./WriterBase";
export declare class WriterLE extends WriterBase implements IWriter {
writeShort(value: number): this;
writeUShort(value: number): this;
writeInt(value: number): this;
writeUInt(value: number): this;
writeLong(value: number | bigint): this;
writeULong(value: number | bigint): this;
writeFloat(value: number): this;
writeDouble(value: number): this;
writeShortString(text: string): this;
writeString(text: string): this;
writeString16(text: string): this;
}

View file

@ -1,130 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WriterLE = void 0;
const WriterBase_1 = require("./WriterBase");
class WriterLE extends WriterBase_1.WriterBase {
writeShort(value) {
if (this.resizable) {
const buffer = Buffer.alloc(2);
buffer.writeInt16LE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeInt16LE(value, this.offset);
this.offset += 2;
}
return this;
}
writeUShort(value) {
if (this.resizable) {
const buffer = Buffer.alloc(2);
buffer.writeUInt16LE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeUInt16LE(value, this.offset);
this.offset += 2;
}
return this;
}
writeInt(value) {
if (this.resizable) {
const buffer = Buffer.alloc(4);
buffer.writeInt32LE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeInt32LE(value, this.offset);
this.offset += 4;
}
return this;
}
writeUInt(value) {
if (this.resizable) {
const buffer = Buffer.alloc(4);
buffer.writeUInt32LE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeUInt32LE(value, this.offset);
this.offset += 4;
}
return this;
}
writeLong(value) {
if (typeof (value) !== "bigint") {
value = BigInt(value);
}
if (this.resizable) {
const buffer = Buffer.alloc(8);
buffer.writeBigInt64LE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeBigInt64LE(value, this.offset);
this.offset += 8;
}
return this;
}
writeULong(value) {
if (typeof (value) !== "bigint") {
value = BigInt(value);
}
if (this.resizable) {
const buffer = Buffer.alloc(8);
buffer.writeBigUint64LE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeBigUint64LE(value, this.offset);
this.offset += 8;
}
return this;
}
writeFloat(value) {
if (this.resizable) {
const buffer = Buffer.alloc(4);
buffer.writeFloatLE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeFloatLE(value, this.offset);
this.offset += 4;
}
return this;
}
writeDouble(value) {
if (this.resizable) {
const buffer = Buffer.alloc(8);
buffer.writeDoubleLE(value);
this.writeBuffer(buffer);
}
else {
this.buffer.writeDoubleLE(value, this.offset);
this.offset += 8;
}
return this;
}
writeShortString(text) {
this.writeUByte(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUByte(text.charCodeAt(i));
}
return this;
}
writeString(text) {
this.writeUShort(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUByte(text.charCodeAt(i));
}
return this;
}
writeString16(text) {
this.writeUShort(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUShort(text.charCodeAt(i));
}
return this;
}
}
exports.WriterLE = WriterLE;

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "bufferstuff", "name": "bufferstuff",
"version": "1.0.0", "version": "1.1.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bufferstuff", "name": "bufferstuff",
"version": "1.0.0", "version": "1.1.2",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"check-outdated": "^2.11.0", "check-outdated": "^2.11.0",