Skip to content

Commit 9502f87

Browse files
fix. plugin install
1 parent e20f78d commit 9502f87

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/fileSystem/ftp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class FtpClient {
142142
async writeFile(content = "") {
143143
await this.#connectIfNotConnected();
144144
const localFile = this.#cacheFile;
145-
await internalFs.writeFile(localFile, content, true, false);
145+
await internalFs.writeToFile(localFile, content, true, false);
146146

147147
return new Promise((resolve, reject) => {
148148
ftp.uploadFile(
@@ -160,7 +160,7 @@ class FtpClient {
160160
async createFile(name, content = "") {
161161
await this.#connectIfNotConnected();
162162
const localFile = this.#cacheFile;
163-
await internalFs.writeFile(localFile, content, true, false);
163+
await internalFs.writeToFile(localFile, content, true, false);
164164

165165
return new Promise((resolve, reject) => {
166166
ftp.uploadFile(

src/fileSystem/internalFs.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const internalFs = {
5757
* Instead, it must be possible for it to be created newly at call time. The default is true.
5858
* @returns {Promise<string>} URL where the file was written into.
5959
*/
60-
writeFile(filename, udata, create = false, exclusive = true) {
60+
writeToFile(filename, udata, create = false, exclusive = true) {
61+
console.log(Filesystem.writeFile);
6162
exclusive = create ? exclusive : false;
6263
const name = filename.split("/").pop();
6364

@@ -73,20 +74,22 @@ const internalFs = {
7374

7475
reject = setMessage(reject);
7576

76-
if (
77-
udata instanceof ArrayBuffer ||
78-
Object.prototype.toString.call(udata) === "[object ArrayBuffer]"
79-
) {
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
77+
if (typeof udata === "string") {
8578
options.data = udata;
8679
options.encoding = Encoding.UTF8;
8780
} else {
88-
reject("Unsupported udata type");
89-
return;
81+
function arrayBufferToBase64(buffer) {
82+
let binary = "";
83+
const bytes = new Uint8Array(buffer);
84+
const len = bytes.byteLength;
85+
for (let i = 0; i < len; i++) {
86+
binary += String.fromCharCode(bytes[i]);
87+
}
88+
return btoa(binary);
89+
}
90+
91+
options.data = arrayBufferToBase64(udata);
92+
options.encoding = Encoding.BASE64;
9093
}
9194

9295
Filesystem.writeFile(options)
@@ -199,7 +202,7 @@ const internalFs = {
199202
resolve({ data: readFileResult.data });
200203
})
201204
.catch((error) => {
202-
console.error(
205+
console.log(
203206
`Failed to Read File contents of "${filename}", error: `,
204207
error,
205208
);
@@ -552,10 +555,15 @@ function createFs(url) {
552555
if (typeof content === "string" && encoding) {
553556
content = await encode(content, encoding);
554557
}
555-
return internalFs.writeFile(url, content, false, false);
558+
return internalFs.writeToFile(url, content, false, false);
556559
},
557560
createFile(name, data) {
558-
return internalFs.writeFile(Url.join(url, name), data || "", true, true);
561+
return internalFs.writeToFile(
562+
Url.join(url, name),
563+
data || "",
564+
true,
565+
true,
566+
);
559567
},
560568
createDirectory(name) {
561569
return internalFs.createDir(url, name);

src/fileSystem/sftp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class SftpClient {
177177
await this.connect();
178178
}
179179

180-
await internalFs.writeFile(localFilename, content, true, false);
180+
await internalFs.writeToFile(localFilename, content, true, false);
181181
const remoteFile = this.#safeName(filename);
182182
sftp.putFile(remoteFile, localFilename, resolve, reject);
183183
} catch (err) {

0 commit comments

Comments
 (0)