@kikiutils/shared 14.0.0 → 14.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buffer.d.ts +18 -19
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +22 -20
- package/dist/buffer.js.map +1 -1
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +14 -19
- package/src/buffer.ts +23 -20
- package/src/types/index.ts +1 -1
package/dist/buffer.d.ts
CHANGED
|
@@ -4,34 +4,33 @@ import { Buffer } from "node:buffer";
|
|
|
4
4
|
//#region src/buffer.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Converts
|
|
7
|
+
* Converts various binary data types to a Node.js Buffer.
|
|
8
8
|
*
|
|
9
|
-
* This function provides a unified way to convert
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* This function provides a unified, efficient way to convert different binary formats
|
|
10
|
+
* (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.
|
|
11
|
+
* It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure
|
|
12
|
+
* optimal performance.
|
|
12
13
|
*
|
|
13
|
-
* @param {Blob | Buffer | File} input - The input to convert
|
|
14
|
+
* @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.
|
|
15
|
+
* Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.
|
|
14
16
|
*
|
|
15
|
-
* @returns {Promise<Buffer>} A
|
|
17
|
+
* @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.
|
|
16
18
|
*
|
|
17
19
|
* @example
|
|
18
20
|
* ```typescript
|
|
19
|
-
* import { toBuffer } from '@kikiutils/shared/
|
|
21
|
+
* import { toBuffer } from '@kikiutils/shared/buffer';
|
|
20
22
|
*
|
|
21
|
-
* //
|
|
22
|
-
* const
|
|
23
|
-
* const
|
|
24
|
-
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
23
|
+
* // From ArrayBuffer
|
|
24
|
+
* const ab = new ArrayBuffer(8);
|
|
25
|
+
* const bufferFromAB = await toBuffer(ab);
|
|
25
26
|
*
|
|
26
|
-
* //
|
|
27
|
-
* const
|
|
28
|
-
* const
|
|
29
|
-
* console.log(result2.toString()); // 'Hello from Blob'
|
|
27
|
+
* // From Uint8Array (Zero-copy)
|
|
28
|
+
* const u8 = new Uint8Array([10, 20, 30]);
|
|
29
|
+
* const bufferFromU8 = await toBuffer(u8);
|
|
30
30
|
*
|
|
31
|
-
* //
|
|
32
|
-
* const
|
|
33
|
-
* const
|
|
34
|
-
* console.log(result3.toString()); // 'File content'
|
|
31
|
+
* // From Blob or File
|
|
32
|
+
* const blob = new Blob(['data'], { type: 'text/plain' });
|
|
33
|
+
* const bufferFromBlob = await toBuffer(blob);
|
|
35
34
|
* ```
|
|
36
35
|
*/
|
|
37
36
|
declare function toBuffer(input: BinaryInput): Promise<Buffer<ArrayBufferLike>>;
|
package/dist/buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAsB,QAAA,QAAgB,cAAW,QAAA,OAAA"}
|
package/dist/buffer.js
CHANGED
|
@@ -2,39 +2,41 @@ import { Buffer } from "node:buffer";
|
|
|
2
2
|
|
|
3
3
|
//#region src/buffer.ts
|
|
4
4
|
/**
|
|
5
|
-
* Converts
|
|
5
|
+
* Converts various binary data types to a Node.js Buffer.
|
|
6
6
|
*
|
|
7
|
-
* This function provides a unified way to convert
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* This function provides a unified, efficient way to convert different binary formats
|
|
8
|
+
* (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.
|
|
9
|
+
* It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure
|
|
10
|
+
* optimal performance.
|
|
10
11
|
*
|
|
11
|
-
* @param {Blob | Buffer | File} input - The input to convert
|
|
12
|
+
* @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.
|
|
13
|
+
* Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.
|
|
12
14
|
*
|
|
13
|
-
* @returns {Promise<Buffer>} A
|
|
15
|
+
* @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.
|
|
14
16
|
*
|
|
15
17
|
* @example
|
|
16
18
|
* ```typescript
|
|
17
|
-
* import { toBuffer } from '@kikiutils/shared/
|
|
19
|
+
* import { toBuffer } from '@kikiutils/shared/buffer';
|
|
18
20
|
*
|
|
19
|
-
* //
|
|
20
|
-
* const
|
|
21
|
-
* const
|
|
22
|
-
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
21
|
+
* // From ArrayBuffer
|
|
22
|
+
* const ab = new ArrayBuffer(8);
|
|
23
|
+
* const bufferFromAB = await toBuffer(ab);
|
|
23
24
|
*
|
|
24
|
-
* //
|
|
25
|
-
* const
|
|
26
|
-
* const
|
|
27
|
-
* console.log(result2.toString()); // 'Hello from Blob'
|
|
25
|
+
* // From Uint8Array (Zero-copy)
|
|
26
|
+
* const u8 = new Uint8Array([10, 20, 30]);
|
|
27
|
+
* const bufferFromU8 = await toBuffer(u8);
|
|
28
28
|
*
|
|
29
|
-
* //
|
|
30
|
-
* const
|
|
31
|
-
* const
|
|
32
|
-
* console.log(result3.toString()); // 'File content'
|
|
29
|
+
* // From Blob or File
|
|
30
|
+
* const blob = new Blob(['data'], { type: 'text/plain' });
|
|
31
|
+
* const bufferFromBlob = await toBuffer(blob);
|
|
33
32
|
* ```
|
|
34
33
|
*/
|
|
35
34
|
async function toBuffer(input) {
|
|
36
35
|
if (Buffer.isBuffer(input)) return input;
|
|
37
|
-
return Buffer.from(
|
|
36
|
+
if (input instanceof ArrayBuffer) return Buffer.from(input);
|
|
37
|
+
if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
38
|
+
if (typeof input.arrayBuffer === "function") return Buffer.from(await input.arrayBuffer());
|
|
39
|
+
throw new TypeError("The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).");
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
//#endregion
|
package/dist/buffer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts
|
|
1
|
+
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts various binary data types to a Node.js Buffer.\n *\n * This function provides a unified, efficient way to convert different binary formats\n * (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.\n * It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure\n * optimal performance.\n *\n * @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.\n * Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.\n *\n * @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.\n *\n * @example\n * ```typescript\n * import { toBuffer } from '@kikiutils/shared/buffer';\n *\n * // From ArrayBuffer\n * const ab = new ArrayBuffer(8);\n * const bufferFromAB = await toBuffer(ab);\n *\n * // From Uint8Array (Zero-copy)\n * const u8 = new Uint8Array([10, 20, 30]);\n * const bufferFromU8 = await toBuffer(u8);\n *\n * // From Blob or File\n * const blob = new Blob(['data'], { type: 'text/plain' });\n * const bufferFromBlob = await toBuffer(blob);\n * ```\n */\nexport async function toBuffer(input: BinaryInput) {\n if (Buffer.isBuffer(input)) return input;\n if (input instanceof ArrayBuffer) return Buffer.from(input);\n if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());\n // eslint-disable-next-line style/max-len\n throw new TypeError('The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAsB,SAAS,OAAoB;AAC/C,KAAI,OAAO,SAAS,MAAM,CAAE,QAAO;AACnC,KAAI,iBAAiB,YAAa,QAAO,OAAO,KAAK,MAAM;AAC3D,KAAI,iBAAiB,WAAY,QAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,WAAW;AACrG,KAAI,OAAO,MAAM,gBAAgB,WAAY,QAAO,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAE1F,OAAM,IAAI,UAAU,sGAAsG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","names":[],"sources":["../../src/classes/path.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAyBY,wBAAA,UAAkC;KACzC,uDAAuD,WAAW
|
|
1
|
+
{"version":3,"file":"path.d.ts","names":[],"sources":["../../src/classes/path.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAyBY,wBAAA,UAAkC;KACzC,uDAAuD,WAAW;AAD3D,KAEA,QAAA,GAAW,EAAA,CAAG,QAFU,GAEC,IAFD;AAAkB;AAEtD;AAQA;;;;AA+C8B,cA/CjB,IAAA,CA+C0B;EAAqB,CAAA,OAAA;EAO/B,WAAA,CAAA,GAAA,KAAA,EAnDH,QAmDG,EAAA;EAAU,CA1ClC,MAAA,CAAO,WAAA,EA0C2B,IAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAgB5B;;;EA4B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,CAAA,CAAA,GAAA,IAAA,CAAA,EA3J5C,OA2J4C,CAAA,MAAA,EAAA,CAAA;EAOzC,OAAA,CAAA,IAAA,EAhKI,QAgKJ,EAAA,OAAA,EAAA,QAAA,GAAA;IAOyB,QAAA,EAAA,QAAA;IAAc,SAAA,CAAA,EAAA,OAAA;IAAA,aAAA,CAAA,EAAA,KAAA;MA/J1C,QAAQ;gBAED,oBAEF,kBACC,EAAA,CAAG;;;cAKT,QAAQ;gBAED,mBACG,EAAA,CAAG;;;MAIb,QAAQ,EAAA,CAAG;gBAEJ;;;;MAMP,QAAQ,EAAA,CAAG,OAAO;;;;sBAUZ;;WAEQ,EAAA,CAAG;cAGjB,QAAQ;qBAGF;cACW;WACH,EAAA,CAAG;OAEZ,iBACL;sBAIS,YACA,EAAA,CAAG;WACM,EAAA,CAAG;OAEd,wBAEP,QAAQ;;;;kBAQK,WAAQ;;;;cAOZ,2BAA2B,GAAA,CAAI,MAAG;;;;iBAO/B,2BAA2B,GAAA,CAAI,SAAM;;;;cAQzC,EAAA,CAAG;;MAGX,QAAQ,EAAA,CAAG;aAEJ,EAAA,CAAG;;MAGV,QAAQ,EAAA,CAAG;cACF,EAAA,CAAG,cAAc,QAAQ,EAAA,CAAG,cAAc,EAAA,CAAG;;;;oBAQvC,2BAA2B,GAAA,CAAI,YAAS;;;;YAOpD;;;;qBAOa,2BAA2B,GAAA,CAAI,aAAU;;;;sBASxC,OAAA,CAAQ,4BAAyB;;;;qBAAjC,OAAA,CAAQ,8BAAyB;;;;qBAAjC,OAAA,CAAQ,8BAAyB;;;;8BAiBnB,gBAAa,QAAA;;;;YAOzC;;;;iCAOyB,iBAAc"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Blob as Blob$1, Buffer, File as File$1 } from "node:buffer";
|
|
|
3
3
|
|
|
4
4
|
//#region src/types/index.d.ts
|
|
5
5
|
type AnyRecord = Record<string, any>;
|
|
6
|
-
type BinaryInput = Blob | Buffer | File | Blob$1 | File$1;
|
|
6
|
+
type BinaryInput = ArrayBuffer | Blob | Buffer | File | Blob$1 | File$1 | Uint8Array;
|
|
7
7
|
type Booleanish = 'false' | 'true' | boolean;
|
|
8
8
|
type MaybePartial<T> = Partial<T> | T;
|
|
9
9
|
type MaybeReadonly<T> = Readonly<T> | T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;KAQY,SAAA,GAAY;KACZ,WAAA,GAAc,OAAO,SAAS,OAAO,SAAW;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;KAQY,SAAA,GAAY;KACZ,WAAA,GAAc,cAAc,OAAO,SAAS,OAAO,SAAW,SAAW;AADzE,KAEA,UAAA,GAFS,OAAG,GAAM,MAAA,GAAA,OAAA;AAClB,KAEA,YAFW,CAAA,CAAA,CAAA,GAEO,OAFP,CAEe,CAFf,CAAA,GAEoB,CAFpB;AAAG,KAGd,aAHc,CAAA,CAAA,CAAA,GAGK,QAHL,CAGc,CAHd,CAAA,GAGmB,CAHnB;AAAc,KAI5B,QAJ4B,CAAA,CAAA,CAAA,GAAA,IAAA,GAIP,CAJO;AAAO,KAKnC,SAAA,GALmC,MAAA,GAAA,MAAA;AAAS,KAM5C,aAN4C,CAAA,UAAA,MAAA,GAAA,EAAA,CAAA,CAAA,GAMJ,OANI,CAMI,MANJ,CAMW,CANX,EAMc,CANd,CAAA,CAAA;AAAO,KAOnD,qBAPmD,CAAA,UAAA,MAAA,GAAA,EAAA,CAAA,CAAA,GAOH,QAPG,CAOM,aAPN,CAOoB,CAPpB,EAOuB,CAPvB,CAAA,CAAA;AAAW,KAQ9D,cAR8D,CAAA,UAAA,MAAA,GAAA,EAAA,CAAA,CAAA,GAQrB,QARqB,CAQZ,MARY,CAQL,CARK,EAQF,CARE,CAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.1.0",
|
|
5
5
|
"description": "A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@noble/hashes": "^2.0.0",
|
|
71
71
|
"@types/fs-extra": "^11.0.4",
|
|
72
72
|
"@types/jsonfile": "^6.1.4",
|
|
73
|
-
"@types/node": "
|
|
73
|
+
"@types/node": ">= 24",
|
|
74
74
|
"@types/ssh2": "^1.15.5",
|
|
75
75
|
"async-validator": "^4.2.5",
|
|
76
76
|
"bson": "^7.0.0",
|
|
@@ -85,7 +85,6 @@
|
|
|
85
85
|
"node-ssh": "^13.2.1",
|
|
86
86
|
"pino": "^10.0.0",
|
|
87
87
|
"pino-pretty": "^13.1.1",
|
|
88
|
-
"superjson": "^2.2.2",
|
|
89
88
|
"vue": "^3.5.21",
|
|
90
89
|
"vue-router": "^4.5.1"
|
|
91
90
|
},
|
|
@@ -144,9 +143,6 @@
|
|
|
144
143
|
"pino-pretty": {
|
|
145
144
|
"optional": true
|
|
146
145
|
},
|
|
147
|
-
"superjson": {
|
|
148
|
-
"optional": true
|
|
149
|
-
},
|
|
150
146
|
"vue": {
|
|
151
147
|
"optional": true
|
|
152
148
|
},
|
|
@@ -155,15 +151,15 @@
|
|
|
155
151
|
}
|
|
156
152
|
},
|
|
157
153
|
"devDependencies": {
|
|
158
|
-
"@antfu/eslint-config": "^6.3
|
|
154
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
159
155
|
"@kikiutils/eslint-config": "^5.0.0",
|
|
160
156
|
"@kikiutils/tsconfigs": "^5.0.5",
|
|
161
157
|
"@noble/hashes": "^2.0.1",
|
|
162
158
|
"@types/fs-extra": "^11.0.4",
|
|
163
159
|
"@types/jsonfile": "^6.1.4",
|
|
164
|
-
"@types/node": "^
|
|
160
|
+
"@types/node": "^25.0.3",
|
|
165
161
|
"@types/ssh2": "^1.15.5",
|
|
166
|
-
"@vitest/coverage-v8": "^4.0.
|
|
162
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
167
163
|
"async-validator": "^4.2.5",
|
|
168
164
|
"bson": "^7.0.0",
|
|
169
165
|
"changelogen": "^0.6.2",
|
|
@@ -172,24 +168,23 @@
|
|
|
172
168
|
"date-fns": "^4.1.0",
|
|
173
169
|
"decimal.js": "^10.6.0",
|
|
174
170
|
"depcheck": "^1.4.7",
|
|
175
|
-
"element-plus": "^2.
|
|
176
|
-
"fs-extra": "^11.3.
|
|
177
|
-
"jsdom": "^27.
|
|
171
|
+
"element-plus": "^2.13.0",
|
|
172
|
+
"fs-extra": "^11.3.3",
|
|
173
|
+
"jsdom": "^27.4.0",
|
|
178
174
|
"lru-cache": "^11.2.4",
|
|
179
175
|
"millify": "^6.1.0",
|
|
180
|
-
"msgpackr": "^1.11.
|
|
176
|
+
"msgpackr": "^1.11.8",
|
|
181
177
|
"node-ssh": "^13.2.1",
|
|
182
178
|
"pino": "^10.1.0",
|
|
183
179
|
"pino-pretty": "^13.1.3",
|
|
184
|
-
"publint": "^0.3.
|
|
185
|
-
"superjson": "^2.2.6",
|
|
180
|
+
"publint": "^0.3.16",
|
|
186
181
|
"ts-unused-exports": "^11.0.1",
|
|
187
|
-
"tsdown": "^0.
|
|
182
|
+
"tsdown": "^0.18.4",
|
|
188
183
|
"typescript": "^5.9.3",
|
|
189
184
|
"unplugin-unused": "^0.5.6",
|
|
190
|
-
"vitest": "^4.0.
|
|
191
|
-
"vue": "^3.5.
|
|
192
|
-
"vue-router": "^4.6.
|
|
185
|
+
"vitest": "^4.0.16",
|
|
186
|
+
"vue": "^3.5.26",
|
|
187
|
+
"vue-router": "^4.6.4"
|
|
193
188
|
},
|
|
194
189
|
"pnpm": {
|
|
195
190
|
"onlyBuiltDependencies": [
|
package/src/buffer.ts
CHANGED
|
@@ -3,37 +3,40 @@ import { Buffer } from 'node:buffer';
|
|
|
3
3
|
import type { BinaryInput } from './types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Converts
|
|
6
|
+
* Converts various binary data types to a Node.js Buffer.
|
|
7
7
|
*
|
|
8
|
-
* This function provides a unified way to convert
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* This function provides a unified, efficient way to convert different binary formats
|
|
9
|
+
* (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.
|
|
10
|
+
* It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure
|
|
11
|
+
* optimal performance.
|
|
11
12
|
*
|
|
12
|
-
* @param {Blob | Buffer | File} input - The input to convert
|
|
13
|
+
* @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.
|
|
14
|
+
* Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.
|
|
13
15
|
*
|
|
14
|
-
* @returns {Promise<Buffer>} A
|
|
16
|
+
* @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* ```typescript
|
|
18
|
-
* import { toBuffer } from '@kikiutils/shared/
|
|
20
|
+
* import { toBuffer } from '@kikiutils/shared/buffer';
|
|
19
21
|
*
|
|
20
|
-
* //
|
|
21
|
-
* const
|
|
22
|
-
* const
|
|
23
|
-
* console.log(result1); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
|
|
22
|
+
* // From ArrayBuffer
|
|
23
|
+
* const ab = new ArrayBuffer(8);
|
|
24
|
+
* const bufferFromAB = await toBuffer(ab);
|
|
24
25
|
*
|
|
25
|
-
* //
|
|
26
|
-
* const
|
|
27
|
-
* const
|
|
28
|
-
* console.log(result2.toString()); // 'Hello from Blob'
|
|
26
|
+
* // From Uint8Array (Zero-copy)
|
|
27
|
+
* const u8 = new Uint8Array([10, 20, 30]);
|
|
28
|
+
* const bufferFromU8 = await toBuffer(u8);
|
|
29
29
|
*
|
|
30
|
-
* //
|
|
31
|
-
* const
|
|
32
|
-
* const
|
|
33
|
-
* console.log(result3.toString()); // 'File content'
|
|
30
|
+
* // From Blob or File
|
|
31
|
+
* const blob = new Blob(['data'], { type: 'text/plain' });
|
|
32
|
+
* const bufferFromBlob = await toBuffer(blob);
|
|
34
33
|
* ```
|
|
35
34
|
*/
|
|
36
35
|
export async function toBuffer(input: BinaryInput) {
|
|
37
36
|
if (Buffer.isBuffer(input)) return input;
|
|
38
|
-
return Buffer.from(
|
|
37
|
+
if (input instanceof ArrayBuffer) return Buffer.from(input);
|
|
38
|
+
if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
39
|
+
if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());
|
|
40
|
+
// eslint-disable-next-line style/max-len
|
|
41
|
+
throw new TypeError('The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).');
|
|
39
42
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
export type { FilteredKeyPath } from './filtered-key-path';
|
|
8
8
|
|
|
9
9
|
export type AnyRecord = Record<string, any>;
|
|
10
|
-
export type BinaryInput = Blob | Buffer | File | NodeBlob | NodeFile;
|
|
10
|
+
export type BinaryInput = ArrayBuffer | Blob | Buffer | File | NodeBlob | NodeFile | Uint8Array;
|
|
11
11
|
export type Booleanish = 'false' | 'true' | boolean;
|
|
12
12
|
export type MaybePartial<T> = Partial<T> | T;
|
|
13
13
|
export type MaybeReadonly<T> = Readonly<T> | T;
|