bufferStuff/index.ts

30 lines
798 B
TypeScript
Raw Normal View History

2023-10-24 12:04:07 +01:00
// Copyright (c) Holly Stubbs (tgpholly) - Licensed under MIT
// Check LICENSE in repository root for more information.
2023-04-28 16:47:02 +01:00
import { IReader } from "./readers/IReader";
import { IWriter } from "./writers/IWriter";
import { ReaderBE } from "./readers/ReaderBE";
import { ReaderLE } from "./readers/ReaderLE";
import { WriterBE } from "./writers/WriterBE";
import { WriterLE } from "./writers/WriterLE";
2023-05-12 14:04:33 +01:00
export enum Endian {
LE,
BE
}
2023-04-28 16:47:02 +01:00
export function createReader(endianness:Endian, buffer:Buffer) : IReader {
if (endianness === Endian.LE) {
return new ReaderLE(buffer);
} else {
return new ReaderBE(buffer);
}
}
export function createWriter(endianness:Endian, size?:number) : IWriter {
if (endianness === Endian.LE) {
return new WriterLE(size);
} else {
return new WriterBE(size);
}
}