From 87273cbbbdc3e9ac4e57f11be231dd542bd15e60 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Thu, 25 Apr 2024 18:06:04 +0200 Subject: [PATCH] fix(core): update --- ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 6def539..4bae04f 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartbuffer', - version: '3.0.2', + version: '3.0.3', description: 'A library for managing ArrayBufferLike structures including conversion between Base64 and Uint8Array, and buffer validation.' } diff --git a/ts/index.ts b/ts/index.ts index 6cd46a7..1cb4edd 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -12,7 +12,7 @@ export function base64ToUint8Array(base64: string): Uint8Array { export const isUint8Array = (obj: any): obj is Uint8Array => { return plugins.uInt8ArrayExtras.isUint8Array(obj); -} +}; export function isBufferLike(obj: any): obj is ArrayBufferLike | Buffer { // Check for ArrayBufferLike objects in any environment @@ -26,4 +26,13 @@ export function isBufferLike(obj: any): obj is ArrayBufferLike | Buffer { } return false; -} \ No newline at end of file +} + +export function convertBufferToPureUint8Array(bufferArg: Buffer) { + // Create a new Uint8Array with the same length as the buffer + const uint8Array: Uint8Array = new Uint8Array(bufferArg.length); + + // Copy the contents of the Buffer to the new Uint8Array + uint8Array.set(bufferArg); + return uint8Array; +}