File tree Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,19 @@ export default function vitePluginArraybuffer(): PluginOption {
21
21
const buffer = await promises . readFile ( file )
22
22
const b64 = buffer . toString ( "base64" )
23
23
24
- return `export default new Uint8Array(
25
- Buffer.from("${ b64 } ", "base64")
26
- ).buffer`
24
+ return `
25
+ function toUint8(b64) {
26
+ let bin = atob(b64);
27
+ let len = bin.length;
28
+ let bytes = new Uint8Array(len);
29
+ for (let i = 0; i < len; i++) {
30
+ bytes[i] = bin.charCodeAt(i);
31
+ }
32
+ return bytes;
33
+ }
34
+
35
+ export default toUint8("${ b64 } ").buffer
36
+ `
27
37
}
28
38
if ( id . endsWith ( "?uint8array" ) ) {
29
39
const file = id . slice ( 0 , - 11 )
@@ -32,9 +42,19 @@ export default function vitePluginArraybuffer(): PluginOption {
32
42
const buffer = await promises . readFile ( file )
33
43
const b64 = buffer . toString ( "base64" )
34
44
35
- return `export default new Uint8Array(
36
- Buffer.from("${ b64 } ", "base64")
37
- )`
45
+ return `
46
+ function toUint8(b64) {
47
+ let bin = atob(b64);
48
+ let len = bin.length;
49
+ let bytes = new Uint8Array(len);
50
+ for (let i = 0; i < len; i++) {
51
+ bytes[i] = bin.charCodeAt(i);
52
+ }
53
+ return bytes;
54
+ }
55
+
56
+ export default toUint8("${ b64 } ")
57
+ `
38
58
}
39
59
40
60
return ;
You can’t perform that action at this time.
0 commit comments