@ntf/buffer
v1.3.0
Published
Another binary data manipulation library
Maintainers
Readme
@ntf/buffer
Another binary data manipulation library
Why
Because I like reinventing the wheel :)
Installation
Use your favourite package manager, idk
npm install @ntf/bufferyarn add @ntf/bufferpnpm install @ntf/bufferUsage
Importing
This library can be used in CommonJS and ESModule environments
const { ... } = require("@ntf/buffer");import { ... } from "@ntf/buffer";MemoryRegion
The class MemoryRegion is a view of an array buffer, it wraps around DataView. Unlike Typed Arrays and NodeJS's Buffer it can do the following:
- reading/writing data will cause to step to the next data in the region (like a stream or better yet: the Java
DataInputStreamandDataOutputStreamclass) - you can change the positions with the
readOffset/writeOffsetattribute or their methodssetReadOffset/setWriteOffset - you can allocate a zero-filled buffer with the static
allocatemethod - the static methods
fromArrayBufferView/fromAsyncconvertsBlob,Responseinstances and any kind of Typed Array to aMemoryRegion(this includes the NodeJSBufferclass because it's just aUint8Array~~but with shitty read/write functions in my opinion~~) - merge any kind of binary data into one with the static method
merge
import { MemoryRegion } from "@ntf/buffer";
const myVeryCoolBuffer = MemoryRegion.allocate(100); // allocates a zero-filled memory region with the size of 100 bytes
const someRandomAssBuffer = await Buffer.fromAsync(someRandomAssBlobOrResponse) // this static method returns a Promise<MemoryRegion>License stuff that nobody reads
Just like any Open Source Project this has a License, the MIT License
