Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
bb89564339 | |||
f480be9917 | |||
11bf0d9dbb | |||
c58cc2b0df | |||
87273cbbbd | |||
bebc8b0ede | |||
46e5217fc0 | |||
ebb539e824 | |||
63e3b492e6 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartbuffer",
|
"name": "@push.rocks/smartbuffer",
|
||||||
"version": "3.0.0",
|
"version": "3.0.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A library for managing ArrayBufferLike structures including conversion between Base64 and Uint8Array, and buffer validation.",
|
"description": "A library for managing ArrayBufferLike structures including conversion between Base64 and Uint8Array, and buffer validation.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -49,5 +49,10 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"uint8array-extras": "^1.1.0"
|
"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 = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartbuffer',
|
name: '@push.rocks/smartbuffer',
|
||||||
version: '3.0.0',
|
version: '3.0.4',
|
||||||
description: 'A library for managing ArrayBufferLike structures including conversion between Base64 and Uint8Array, and buffer validation.'
|
description: 'A library for managing ArrayBufferLike structures including conversion between Base64 and Uint8Array, and buffer validation.'
|
||||||
}
|
}
|
||||||
|
25
ts/index.ts
25
ts/index.ts
@ -12,4 +12,27 @@ export function base64ToUint8Array(base64: string): Uint8Array {
|
|||||||
|
|
||||||
export const isUint8Array = (obj: any): obj is Uint8Array => {
|
export const isUint8Array = (obj: any): obj is Uint8Array => {
|
||||||
return plugins.uInt8ArrayExtras.isUint8Array(obj);
|
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') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional check specific to Node.js environment for Buffer objects
|
||||||
|
if (typeof Buffer !== 'undefined' && Buffer.isBuffer) {
|
||||||
|
return Buffer.isBuffer(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
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