Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
bb89564339 | |||
f480be9917 | |||
11bf0d9dbb | |||
c58cc2b0df | |||
87273cbbbd | |||
bebc8b0ede | |||
46e5217fc0 | |||
ebb539e824 | |||
63e3b492e6 | |||
158614c62c | |||
f11114f6dc | |||
f233cb1dcd | |||
866da6f21a |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@push.rocks/smartbuffer",
|
||||
"version": "2.0.2",
|
||||
"version": "3.0.4",
|
||||
"private": false,
|
||||
"description": "A library for managing ArrayBufferLike structures including conversion between Base64 and Uint8Array, and buffer validation.",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -49,5 +49,10 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"uint8array-extras": "^1.1.0"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/smartbuffer",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartbuffer.git"
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartbuffer',
|
||||
version: '2.0.2',
|
||||
version: '3.0.4',
|
||||
description: 'A library for managing ArrayBufferLike structures including conversion between Base64 and Uint8Array, and buffer validation.'
|
||||
}
|
||||
|
15
ts/index.ts
15
ts/index.ts
@ -10,6 +10,10 @@ export function base64ToUint8Array(base64: string): Uint8Array {
|
||||
return plugins.uInt8ArrayExtras.base64ToUint8Array(base64);
|
||||
}
|
||||
|
||||
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
|
||||
if (obj && typeof obj.byteLength === 'number') {
|
||||
@ -22,4 +26,13 @@ export function isBufferLike(obj: any): obj is ArrayBufferLike | Buffer {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function ensurePureUint8Array(bufferArg: Uint8Array | Buffer): Uint8Array {
|
||||
// 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user