Skip to content

Commit bc3e128

Browse files
committed
.
1 parent 9348fc2 commit bc3e128

File tree

2 files changed

+84
-65
lines changed

2 files changed

+84
-65
lines changed

docs/en/guide/webui/api/filesystem.md

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ fun sanitizeModIdWithFile(input: String): String {
2626

2727
For example, the module ID `"mmrl_wpd"` would be sanitized to `"$MmFile"`. Play with this code sample [online](https://pl.kotl.in/uHiACLNTQ)
2828

29+
### Setup
30+
31+
```js
32+
import { FileSystem } from "mmrl"
33+
34+
const fs = new FileSystem("mmrl_wpd")
35+
```
36+
2937
## Methods
3038

31-
### `fileSystem.read(path: string)`
39+
### `fs.read(path: string)`
3240

3341
Reads the contents of a file located at the specified `path`.
3442

@@ -43,13 +51,13 @@ Reads the contents of a file located at the specified `path`.
4351
#### Example:
4452

4553
```javascript
46-
const content = fileSystem.read("/path/to/file.txt");
54+
const content = fs.read("/path/to/file.txt");
4755
console.log(content); // Output the file content
4856
```
4957

5058
---
5159

52-
### `fileSystem.read(path: string, bytes: boolean)`
60+
### `fs.read(path: string, bytes: boolean)`
5361

5462
Reads the contents of a file at the specified `path`. If `bytes` is `true`, the content is returned as a Base64-encoded string.
5563

@@ -65,13 +73,13 @@ Reads the contents of a file at the specified `path`. If `bytes` is `true`, the
6573
#### Example:
6674

6775
```javascript
68-
const base64Content = fileSystem.read("/path/to/image.png", true);
76+
const base64Content = fs.read("/path/to/image.png", true);
6977
console.log(base64Content); // Base64-encoded string
7078
```
7179

7280
---
7381

74-
### `fileSystem.write(path: string, data: string)`
82+
### `fs.write(path: string, data: string)`
7583

7684
Writes the specified `data` to a file at the given `path`. If the file already exists, it will be overwritten.
7785

@@ -87,12 +95,12 @@ Writes the specified `data` to a file at the given `path`. If the file already e
8795
#### Example:
8896

8997
```javascript
90-
fileSystem.write("/path/to/output.txt", "Hello, world!");
98+
fs.write("/path/to/output.txt", "Hello, world!");
9199
```
92100

93101
---
94102

95-
### `fileSystem.readAsBase64(path: string)`
103+
### `fs.readAsBase64(path: string)`
96104

97105
Reads the content of a file at the specified `path` and returns it as a Base64-encoded string.
98106

@@ -107,13 +115,13 @@ Reads the content of a file at the specified `path` and returns it as a Base64-e
107115
#### Example:
108116

109117
```javascript
110-
const base64Content = fileSystem.readAsBase64("/path/to/file.pdf");
118+
const base64Content = fs.readAsBase64("/path/to/file.pdf");
111119
console.log(base64Content); // Base64-encoded string
112120
```
113121

114122
---
115123

116-
### `fileSystem.list(path: string)`
124+
### `fs.list(path: string)`
117125

118126
Lists the files and directories in the specified `path`.
119127

@@ -123,18 +131,18 @@ Lists the files and directories in the specified `path`.
123131

124132
#### Returns:
125133

126-
- `string[] | null`: An array of file and directory names, or `null` if not available.
134+
- `string | null`: An array of file and directory names, or `null` if not available.
127135

128136
#### Example:
129137

130138
```javascript
131-
const fileList = fileSystem.list("/path/to/directory");
132-
console.log(fileList); // ["file1.txt", "file2.txt", "folder1"]
139+
const fileList = fs.list("/path/to/directory");
140+
console.log(fileList.split(",")); // ["file1.txt", "file2.txt", "folder1"]
133141
```
134142

135143
---
136144

137-
### `fileSystem.list(path: string, delimiter: string)`
145+
### `fs.list(path: string, delimiter: string)`
138146

139147
Lists the files and directories in the specified `path`, and allows customization of the delimiter separating the file names.
140148

@@ -145,18 +153,18 @@ Lists the files and directories in the specified `path`, and allows customizatio
145153

146154
#### Returns:
147155

148-
- `string[] | null`: A list of file and directory names, separated by the specified delimiter.
156+
- `string | null`: A list of file and directory names, separated by the specified delimiter.
149157

150158
#### Example:
151159

152160
```javascript
153-
const fileList = fileSystem.list("/path/to/directory", "|");
154-
console.log(fileList); // ["file1.txt|file2.txt|folder1"]
161+
const fileList = fs.list("/path/to/directory", "|");
162+
console.log(fileList.split("|")); // ["file1.txt|file2.txt|folder1"]
155163
```
156164

157165
---
158166

159-
### `fileSystem.size(path: string)`
167+
### `fs.size(path: string)`
160168

161169
Gets the size of the file or directory at the specified `path`.
162170

@@ -171,13 +179,13 @@ Gets the size of the file or directory at the specified `path`.
171179
#### Example:
172180

173181
```javascript
174-
const size = fileSystem.size("/path/to/file.txt");
182+
const size = fs.size("/path/to/file.txt");
175183
console.log(size); // 1024 (size in bytes)
176184
```
177185

178186
---
179187

180-
### `fileSystem.size(path: string, recursive: boolean)`
188+
### `fs.size(path: string, recursive: boolean)`
181189

182190
Gets the size of the file or directory at the specified `path`. If `recursive` is `true`, the size includes all files within subdirectories.
183191

@@ -193,13 +201,13 @@ Gets the size of the file or directory at the specified `path`. If `recursive` i
193201
#### Example:
194202

195203
```javascript
196-
const totalSize = fileSystem.size("/path/to/directory", true);
204+
const totalSize = fs.size("/path/to/directory", true);
197205
console.log(totalSize); // Total size of all files in the directory
198206
```
199207

200208
---
201209

202-
### `fileSystem.stat(path: string)`
210+
### `fs.stat(path: string)`
203211

204212
Gets the status of the file or directory at the specified `path`. This could include properties like the last modified time or size.
205213

@@ -214,13 +222,13 @@ Gets the status of the file or directory at the specified `path`. This could inc
214222
#### Example:
215223

216224
```javascript
217-
const status = fileSystem.stat("/path/to/file.txt");
225+
const status = fs.stat("/path/to/file.txt");
218226
console.log(status); // Numeric status value (e.g., last modified timestamp)
219227
```
220228

221229
---
222230

223-
### `fileSystem.stat(path: string, total: boolean)`
231+
### `fs.stat(path: string, total: boolean)`
224232

225233
Gets the status of the file or directory at the specified `path`, with an option to include the total status for directories (e.g., combined size of all files).
226234

@@ -236,13 +244,13 @@ Gets the status of the file or directory at the specified `path`, with an option
236244
#### Example:
237245

238246
```javascript
239-
const totalStatus = fileSystem.stat("/path/to/directory", true);
247+
const totalStatus = fs.stat("/path/to/directory", true);
240248
console.log(totalStatus); // Total status value (e.g., combined size of all files)
241249
```
242250

243251
---
244252

245-
### `fileSystem.delete(path: string)`
253+
### `fs.delete(path: string)`
246254

247255
Deletes the file or directory at the specified `path`.
248256

@@ -257,13 +265,13 @@ Deletes the file or directory at the specified `path`.
257265
#### Example:
258266

259267
```javascript
260-
const success = fileSystem.delete("/path/to/file.txt");
268+
const success = fs.delete("/path/to/file.txt");
261269
console.log(success); // true if deleted, false otherwise
262270
```
263271

264272
---
265273

266-
### `fileSystem.exists(path: string)`
274+
### `fs.exists(path: string)`
267275

268276
Checks if a file or directory exists at the specified `path`.
269277

@@ -278,7 +286,7 @@ Checks if a file or directory exists at the specified `path`.
278286
#### Example:
279287

280288
```javascript
281-
const exists = fileSystem.exists("/path/to/file.txt");
289+
const exists = fs.exists("/path/to/file.txt");
282290
console.log(exists); // true if the file exists, false otherwise
283291
```
284292

@@ -301,6 +309,8 @@ Creates an instance of the `FileSystem` class with the provided `scope`.
301309
#### Example:
302310

303311
```javascript
304-
const fileSystem = FileSystemFactory("net-switch");
305-
console.log(fileSystem.read("/path/to/file.txt"));
312+
import { FileSystemFactory } from "mmrl"
313+
314+
const fs = FileSystemFactory("net-switch");
315+
console.log(fs.read("/path/to/file.txt"));
306316
```

0 commit comments

Comments
 (0)