forked from crossutility/Quantumult-X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-icloud-storage.js
57 lines (41 loc) · 1 KB
/
sample-icloud-storage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @fileoverview Example to read, write and remove iCloud file
* in the directory of iCloud Drive/Quantumult X/Data/
*
* @supported Quantumult X (v1.0.31-build717)
*
* $iCloud.writeFile(Uint8Array, path), $iCloud.readFile(path), iCloud.removeFile(path)
*/
let filePath = "world/birth.txt";
// let filePath = "birth.txt";
// Write iCloud file.
let writeContent = "Hello World 😀 !";
let encoder = new TextEncoder();
let writeUint8Array = encoder.encode(writeContent);
if ($iCloud.writeFile(writeUint8Array, filePath)) {
console.log("OK");
} else {
console.log("NO");
}
$done();
// Read iCloud file.
/*
let readUint8Array = $iCloud.readFile(filePath);
if (readUint8Array === undefined) {
console.log("NO");
} else {
let textDecoder = new TextDecoder();
let readContent = textDecoder.decode(readUint8Array);
console.log(readContent);
}
$done();
*/
// Remove iCloud file.
/*
if ($iCloud.removeFile(filePath)) {
console.log("OK");
} else {
console.log("NO");
}
$done();
*/