From 380add289058ab1116f7752f6acfd657c4d5db86 Mon Sep 17 00:00:00 2001 From: Holly Date: Fri, 12 May 2023 09:38:26 +0100 Subject: [PATCH] Create README.md --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..46b54fd --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# bufferStuff   [![CodeFactor](https://www.codefactor.io/repository/github/tgpholly/bufferstuff/badge)](https://www.codefactor.io/repository/github/tgpholly/bufferstuff) +A set of utility classes for reading and writing binary data in NodeJS and the browser. + +## Motivations +I tend to write code a lot that needs to read and write from buffers ***and*** this is sometimes in big-endian too, so I decided eventually to make a utility to help me with that which is what you see here. +Originally I had two variants of bufferStuff that were for LE and BE respectively but this got difficult to manage so I rewrote it in TypeScript and added support for both reader / writer types. + +## Usage +You can create an instance of the Reader and Writer classes like this: +```ts +// You *must* be expicit with the endianness +const leReader:IReader = createReader(Endian.LE, buffer); +const beReader:IReader = createReader(Endian.BE, buffer); + +// Size is optional, will dynamically allocate if left empty or 0 +const leWriter:IWriter = createWriter(Endian.LE, ); +const beWriter:IWriter = createWriter(Endian.BE, ); +``` + +I tried to keep it as simple as possible to use, for example if you want to write a (signed) byte you do as follows: +```ts +writer.writeByte(); +``` + +You can find a list of all of the methods for [Writers](https://github.com/tgpholly/bufferStuff/blob/master/writers/IWriter.ts) and [Readers](https://github.com/tgpholly/bufferStuff/blob/master/readers/IReader.ts) in their interface files.