Skip to content

Commit 45c233f

Browse files
fix. file curruption when saving non-text files
1 parent 79cf867 commit 45c233f

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/fileSystem/internalFs.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,30 @@ const internalFs = {
6666
reject("udata is null");
6767
}
6868

69-
let data;
69+
let options = {
70+
path: filename,
71+
recursive: create,
72+
};
73+
74+
reject = setMessage(reject);
75+
7076
if (
7177
udata instanceof ArrayBuffer ||
7278
Object.prototype.toString.call(udata) === "[object ArrayBuffer]"
7379
) {
74-
const decoder = new TextDecoder("utf-8");
75-
data = decoder.decode(udata);
80+
// Binary data — store as base64
81+
options.data = btoa(String.fromCharCode(...new Uint8Array(udata)));
82+
options.encoding = Encoding.BASE64;
83+
} else if (typeof udata === "string") {
84+
// Text data — store as UTF-8
85+
options.data = udata;
86+
options.encoding = Encoding.UTF8;
7687
} else {
77-
data = udata;
88+
reject("Unsupported udata type");
89+
return;
7890
}
7991

80-
reject = setMessage(reject);
81-
Filesystem.writeFile({
82-
path: filename,
83-
data: data,
84-
encoding: Encoding.UTF8,
85-
recursive: create,
86-
})
92+
Filesystem.writeFile(options)
8793
.then((file) => {
8894
console.log(
8995
`Successfully written into (name: ${name}) ${filename} file`,

src/pages/plugin/plugin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,19 @@ export default async function PluginInclude(
7575
const installedPlugin = await fsOperation(
7676
Url.join(PLUGIN_DIR, id, "plugin.json"),
7777
).readFile("json");
78+
79+
console.log(installPlugin);
80+
7881
const { author } = installedPlugin;
82+
83+
console.log(author);
84+
7985
const description = await fsOperation(
8086
Url.join(PLUGIN_DIR, id, installedPlugin.readme),
8187
).readFile("utf8");
88+
89+
console.log(description);
90+
8291
let changelogs = "";
8392
if (installedPlugin.changelogs) {
8493
const changelogPath = Url.join(

0 commit comments

Comments
 (0)