|
4 | 4 | You are currently viewing an unpublished version of the WebUI MX Engine API. This interface is subject to change at any time, including during internal development, alpha stages, and release candidate phases. |
5 | 5 | ::: |
6 | 6 |
|
7 | | -TODO |
| 7 | +::: details TypeScript Type Definition |
| 8 | +```ts |
| 9 | +/** |
| 10 | + * Represents a readable byte stream. |
| 11 | + */ |
| 12 | +interface InputStream { |
| 13 | + /** |
| 14 | + * Reads a single byte from the stream. |
| 15 | + * |
| 16 | + * @returns The byte value, or `-1` if the end of the stream has been reached. |
| 17 | + */ |
| 18 | + read(): number |
| 19 | + |
| 20 | + /** |
| 21 | + * Reads bytes into the provided buffer. |
| 22 | + * |
| 23 | + * @param b Destination buffer. |
| 24 | + * @returns Number of bytes read, or `-1` if the end of the stream has been reached. |
| 25 | + */ |
| 26 | + read(b: Array<number>): number |
| 27 | + |
| 28 | + /** |
| 29 | + * Reads up to `len` bytes into the provided buffer starting at `off`. |
| 30 | + * |
| 31 | + * @param b Destination buffer. |
| 32 | + * @param off Offset within the buffer to begin writing. |
| 33 | + * @param len Maximum number of bytes to read. |
| 34 | + * @returns Number of bytes read, or `-1` if the end of the stream has been reached. |
| 35 | + */ |
| 36 | + read(b: Array<number>, off: number, len: number): number |
| 37 | + |
| 38 | + /** |
| 39 | + * Skips over and discards bytes from the stream. |
| 40 | + * |
| 41 | + * @param n Number of bytes to skip. |
| 42 | + * @returns Actual number of bytes skipped. |
| 43 | + */ |
| 44 | + skip(n: number): number |
| 45 | + |
| 46 | + /** |
| 47 | + * Marks the current position in the stream. |
| 48 | + * |
| 49 | + * @param readLimit Maximum number of bytes that can be read before the mark becomes invalid. |
| 50 | + */ |
| 51 | + mark(readLimit: number): void |
| 52 | + |
| 53 | + /** |
| 54 | + * Resets the stream position to the last marked location. |
| 55 | + */ |
| 56 | + reset(): void |
| 57 | + |
| 58 | + /** |
| 59 | + * Indicates whether this stream supports mark/reset operations. |
| 60 | + */ |
| 61 | + markSupported(): void |
| 62 | + |
| 63 | + /** |
| 64 | + * Returns the number of bytes that can be read without blocking. |
| 65 | + * |
| 66 | + * @returns Number of available bytes. |
| 67 | + */ |
| 68 | + available(): number |
| 69 | + |
| 70 | + /** |
| 71 | + * Closes the stream and releases any associated resources. |
| 72 | + */ |
| 73 | + close(): void |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * Represents a writable byte stream. |
| 78 | + */ |
| 79 | +interface OutputStream { |
| 80 | + /** |
| 81 | + * Writes the provided bytes to the stream. |
| 82 | + * |
| 83 | + * @param chunk Bytes to write. |
| 84 | + */ |
| 85 | + write(chunk: Array<number>): void |
| 86 | + |
| 87 | + /** |
| 88 | + * Closes the stream and releases any associated resources. |
| 89 | + */ |
| 90 | + close(): void |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * Options used when reading or writing files. |
| 95 | + */ |
| 96 | +type FileOptions = { |
| 97 | + /** |
| 98 | + * Character encoding used for file contents. |
| 99 | + * |
| 100 | + * @default "UTF-8" |
| 101 | + */ |
| 102 | + encoding: string |
| 103 | + |
| 104 | + /** |
| 105 | + * File open flags. |
| 106 | + * Use the constants exposed by {@link FileSystem}. |
| 107 | + */ |
| 108 | + flags: number |
| 109 | + |
| 110 | + /** |
| 111 | + * File permission mode. |
| 112 | + */ |
| 113 | + mode: number |
| 114 | +} |
| 115 | + |
| 116 | +/** |
| 117 | + * Provides access to filesystem operations and POSIX-style file flags. |
| 118 | + */ |
| 119 | +interface FileSystem { |
| 120 | + /** |
| 121 | + * Error if the file already exists. |
| 122 | + */ |
| 123 | + O_EXCL: number |
| 124 | + |
| 125 | + /** |
| 126 | + * Do not assign the opened file as the controlling terminal. |
| 127 | + */ |
| 128 | + O_NOCTTY: number |
| 129 | + |
| 130 | + /** |
| 131 | + * Fail if the target path is a symbolic link. |
| 132 | + */ |
| 133 | + O_NOFOLLOW: number |
| 134 | + |
| 135 | + /** |
| 136 | + * Open file in non-blocking mode. |
| 137 | + */ |
| 138 | + O_NONBLOCK: number |
| 139 | + |
| 140 | + /** |
| 141 | + * Open file for read-only access. |
| 142 | + */ |
| 143 | + O_RDONLY: number |
| 144 | + |
| 145 | + /** |
| 146 | + * Open file for both reading and writing. |
| 147 | + */ |
| 148 | + O_RDWR: number |
| 149 | + |
| 150 | + /** |
| 151 | + * Synchronous I/O file integrity completion. |
| 152 | + */ |
| 153 | + O_SYNC: number |
| 154 | + |
| 155 | + /** |
| 156 | + * Synchronized data I/O completion. |
| 157 | + * |
| 158 | + * Below Android 8.1 this value will be `0`. |
| 159 | + */ |
| 160 | + O_DSYNC: number |
| 161 | + |
| 162 | + /** |
| 163 | + * Truncate the file to zero length when opening. |
| 164 | + */ |
| 165 | + O_TRUNC: number |
| 166 | + |
| 167 | + /** |
| 168 | + * Open file for write-only access. |
| 169 | + */ |
| 170 | + O_WRONLY: number |
| 171 | + |
| 172 | + /** |
| 173 | + * Mask for access mode bits. |
| 174 | + */ |
| 175 | + O_ACCMODE: number |
| 176 | + |
| 177 | + /** |
| 178 | + * Append all writes to the end of the file. |
| 179 | + */ |
| 180 | + O_APPEND: number |
| 181 | + |
| 182 | + /** |
| 183 | + * Close the file descriptor on process execution. |
| 184 | + * |
| 185 | + * Below Android 8.1 this value will be `0`. |
| 186 | + */ |
| 187 | + O_CLOEXEC: number |
| 188 | + |
| 189 | + /** |
| 190 | + * Create the file if it does not already exist. |
| 191 | + */ |
| 192 | + O_CREAT: number |
| 193 | + |
| 194 | + /** |
| 195 | + * Reads a file asynchronously. |
| 196 | + * |
| 197 | + * @param path Path to the file. |
| 198 | + * @param options File reading options. |
| 199 | + * @returns The file contents. |
| 200 | + */ |
| 201 | + readFile(path: string, options: FileOptions): Promise<string> |
| 202 | + |
| 203 | + /** |
| 204 | + * Reads a file synchronously. |
| 205 | + * |
| 206 | + * @param path Path to the file. |
| 207 | + * @param options File reading options. |
| 208 | + * @returns The file contents, or `null` if the read fails. |
| 209 | + */ |
| 210 | + readFileSync(path: string, options: FileOptions): string | null |
| 211 | + |
| 212 | + /** |
| 213 | + * Writes a file asynchronously. |
| 214 | + * |
| 215 | + * @param path Path to the file. |
| 216 | + * @param options File writing options. |
| 217 | + */ |
| 218 | + writeFile(path: string, options: FileOptions): Promise<void> |
| 219 | + |
| 220 | + /** |
| 221 | + * Tests whether the current process can access a file. |
| 222 | + * |
| 223 | + * @param path Path to the file. |
| 224 | + * @param mode Access mode to check. |
| 225 | + * @returns `true` if access is allowed; otherwise `false`. |
| 226 | + */ |
| 227 | + access(path: string, mode: number): Promise<boolean> |
| 228 | + |
| 229 | + /** |
| 230 | + * Opens a file as an input stream. |
| 231 | + * |
| 232 | + * @param path Path to the file. |
| 233 | + * @param options Stream open options. The `encoding` option is not applicable. |
| 234 | + * @returns A readable input stream. |
| 235 | + */ |
| 236 | + inputstream( |
| 237 | + path: string, |
| 238 | + options: Omit<FileOptions, "encoding"> |
| 239 | + ): Promise<InputStream> |
| 240 | + |
| 241 | + /** |
| 242 | + * Opens a file as an output stream. |
| 243 | + * |
| 244 | + * @param path Path to the file. |
| 245 | + * @param options Stream open options. The `encoding` option is not applicable. |
| 246 | + * @returns A writable output stream. |
| 247 | + */ |
| 248 | + outputstream( |
| 249 | + path: string, |
| 250 | + options: Omit<FileOptions, "encoding"> |
| 251 | + ): Promise<OutputStream> |
| 252 | +} |
| 253 | + |
| 254 | +/** |
| 255 | + * Global filesystem API instance. |
| 256 | + */ |
| 257 | +declare var fs: FileSystem |
| 258 | +``` |
| 259 | +::: |
0 commit comments