├── index.d.ts ├── .gitignore ├── assembly ├── tsconfig.json ├── index.ts └── as-wasi.ts ├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ └── issues.yml ├── LICENSE ├── package.json ├── bindings.json ├── README.md └── REFERENCE_API_DOCS.md /index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './assembly/index'; 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | build 3 | node_modules 4 | temp-docs 5 | -------------------------------------------------------------------------------- /assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../node_modules/assemblyscript/std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } -------------------------------------------------------------------------------- /assembly/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | WASIError, Descriptor, 3 | Console, Random, Date, Process, EnvironEntry, Environ, CommandLine, FileSystem, FileStat, Time 4 | } from "./as-wasi"; 5 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "04:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: assemblyscript 11 | versions: 12 | - 0.18.0 13 | - 0.18.3 14 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Node.js CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | strategy: 10 | matrix: 11 | node-version: [17.x, 18.x] 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: Use Node.js ${{ matrix.node-version }} 16 | uses: actions/setup-node@v1 17 | with: 18 | node-version: ${{ matrix.node-version }} 19 | - run: npm install 20 | - run: npm run asbuild 21 | -------------------------------------------------------------------------------- /.github/workflows/issues.yml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues 2 | on: 3 | schedule: 4 | - cron: "30 1 * * *" 5 | 6 | jobs: 7 | close-issues: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | issues: write 11 | pull-requests: write 12 | steps: 13 | - uses: actions/stale@v9 14 | with: 15 | stale-issue-message: "This issue is stale because it has been open for 30 days with no activity." 16 | close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." 17 | repo-token: ${{ secrets.GITHUB_TOKEN }} 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2021 Frank Denis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "as-wasi", 3 | "version": "0.6.0", 4 | "scripts": { 5 | "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --debug", 6 | "asbuild:small": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3z ", 7 | "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3", 8 | "asbuild": "npm run asbuild:optimized", 9 | "docs": "npm run docs:clean && npm run docs:typedoc && npm run docs:concat", 10 | "docs:clean": "rimraf temp-docs", 11 | "docs:typedoc": "typedoc --plugin typedoc-plugin-markdown --theme markdown --out temp-docs --tsconfig assembly/tsconfig.json --exclude \"node_modules/**/*\" --readme none assembly", 12 | "docs:concat": "concat-md --decrease-title-levels --dir-name-as-title temp-docs > REFERENCE_API_DOCS.md" 13 | }, 14 | "dependencies": { 15 | "@assemblyscript/wasi-shim": "^0.1" 16 | }, 17 | "devDependencies": { 18 | "assemblyscript": "^0.27", 19 | "concat-md": "^0.5", 20 | "rimraf": "^4.2", 21 | "typedoc": "^0.23", 22 | "typedoc-plugin-markdown": "^3.13" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /bindings.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "abort": "abort" 4 | }, 5 | "wasi_snapshot_preview1": { 6 | "args_get": "__wasi_args_get", 7 | "args_sizes_get": "__wasi_args_sizes_get", 8 | "clock_res_get": "__wasi_clock_res_get", 9 | "clock_time_get": "__wasi_clock_time_get", 10 | "environ_get": "__wasi_environ_get", 11 | "environ_sizes_get": "__wasi_environ_sizes_get", 12 | "fd_advise": "__wasi_fd_advise", 13 | "fd_allocate": "__wasi_fd_allocate", 14 | "fd_close": "__wasi_fd_close", 15 | "fd_datasync": "__wasi_fd_datasync", 16 | "fd_fdstat_get": "__wasi_fd_fdstat_get", 17 | "fd_fdstat_set_flags": "__wasi_fd_fdstat_set_flags", 18 | "fd_fdstat_set_rights": "__wasi_fd_fdstat_set_rights", 19 | "fd_filestat_get": "__wasi_fd_filestat_get", 20 | "fd_filestat_set_size": "__wasi_fd_filestat_set_size", 21 | "fd_filestat_set_times": "__wasi_fd_filestat_set_times", 22 | "fd_pread": "__wasi_fd_pread", 23 | "fd_prestat_dir_name": "__wasi_fd_prestat_dir_name", 24 | "fd_prestat_get": "__wasi_fd_prestat_get", 25 | "fd_pwrite": "__wasi_fd_pwrite", 26 | "fd_read": "__wasi_fd_read", 27 | "fd_readdir": "__wasi_fd_readdir", 28 | "fd_renumber": "__wasi_fd_renumber", 29 | "fd_seek": "__wasi_fd_seek", 30 | "fd_sync": "__wasi_fd_sync", 31 | "fd_tell": "__wasi_fd_tell", 32 | "fd_write": "__wasi_fd_write", 33 | "path_create_directory": "__wasi_path_create_directory", 34 | "path_filestat_get": "__wasi_path_filestat_get", 35 | "path_filestat_set_times": "__wasi_path_filestat_set_times", 36 | "path_link": "__wasi_path_link", 37 | "path_open": "__wasi_path_open", 38 | "path_readlink": "__wasi_path_readlink", 39 | "path_remove_directory": "__wasi_path_remove_directory", 40 | "path_rename": "__wasi_path_rename", 41 | "path_symlink": "__wasi_path_symlink", 42 | "path_unlink_file": "__wasi_path_unlink_file", 43 | "poll_oneoff": "__wasi_poll_oneoff", 44 | "proc_exit": "__wasi_proc_exit", 45 | "random_get": "__wasi_random_get", 46 | "sched_yield": "__wasi_sched_yield" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # as-wasi 2 | 3 | 4 | 5 | ![npm version](https://img.shields.io/npm/v/as-wasi.svg) 6 | ![npm downloads per month](https://img.shields.io/npm/dm/as-wasi.svg) 7 | ![GitHub License](https://img.shields.io/github/license/torch2424/as-wasi.svg) 8 | 9 | 10 | 11 | A high-level AssemblyScript layer for the WebAssembly System Interface (WASI). 🧩 12 | 13 | [WASI](https://wasi.dev) is an API providing access to the external world to WebAssembly modules. AssemblyScript exposes the low-level WASI standard set of system calls. `as-wasi` builds a higher level API on top of the AssemblyScript WASI interface, at a similar level to the [Node API](https://nodejs.org/docs/latest/api/). 🚀 14 | 15 | ## Installation 16 | 17 | You can install `as-wasi` in your project by running the following: 18 | 19 | `npm install --save as-wasi` 20 | 21 | ## Quick Start 22 | 23 | Example usage of the `Console` and `Environ` classes: 24 | 25 | ```typescript 26 | // Import from the installed as-wasi package 27 | import { Console, Environ } from "as-wasi/assembly"; 28 | 29 | // Create an environ instance 30 | let env = new Environ(); 31 | 32 | // Get the HOME Environment variable 33 | let home = env.get("HOME")!; 34 | 35 | // Log the HOME string to stdout 36 | Console.log(home); 37 | ``` 38 | 39 | Here are some exported classes that are commonly used: 40 | 41 | * `FileSystem` - Reading and Writing the user's fileystem. 📁 42 | * `Console` - General logging to stdout and stderr. 🖥️ 43 | * `Environ` - Accessing environment variables, command flags, etc... 🌐 44 | * `Date` - Getting the current system time. 📅 45 | * `Random` - Accessing random numbers. 🤔 46 | * `Time` - Allow sleeping and waiting for events to occur. ⏰ 47 | * And More! See the Reference API in the next section for the full API. 48 | 49 | ## Reference API Docs 50 | 51 | Reference API documentation can be found in [REFERENCE_API_DOCS](./REFERENCE_API_DOCS.md). Documentation is generated using [typedoc](https://typedoc.org/). 52 | 53 | ## Projects using as-wasi 54 | 55 | * [wasmboy](https://github.com/torch2424/wasmboy) - Game Boy / Game Boy Color Emulator Library, 🎮written for WebAssembly using AssemblyScript. 🚀 56 | * [wasmerio/io-devices-lib](https://github.com/wasmerio/io-devices-lib) - Library for interacting with the Wasmer Experimental IO Devices API. Uses WASI for outputting graphics in a framebuffer, and handles mouse/keyboard input. 57 | * [wasm-by-example](https://github.com/torch2424/wasm-by-example) - Wasm By Example is a website with a set of hands-on introduction examples and tutorials for WebAssembly (Wasm). Wasm By Example features `as-wasi` by default for the AssemblyScript WASI examples. 58 | * [wasm-matrix](https://github.com/torch2424/wasm-matrix) - A Matrix effect in your terminal using AssemblyScript 🚀 and WASI 🧩 . This project is a bit older, and uses an older version of `as-wasi`, but still creates a cool effect! 59 | 60 | _If your project is using as-wasi, and you would like to be featured here. Please open a pull request against the README with links to your project, and if appropriate, explaining how as-wasi is being used._ 😊 61 | 62 | ## Contributing 63 | 64 | Contributions are definitely welcome! Feel free to open a PR for small fixes such as typos and things. Larger fixes, or new features should start out as an issue for discussion, in which then a PR should be made. 🥳 65 | 66 | This project will also adhere to the [AssemblyScript Code of Conduct](https://github.com/AssemblyScript/assemblyscript/blob/master/CODE_OF_CONDUCT.md). 67 | 68 | ## License 69 | 70 | [MIT](https://oss.ninja/mit/jedisct1). 📝 71 | -------------------------------------------------------------------------------- /assembly/as-wasi.ts: -------------------------------------------------------------------------------- 1 | import { 2 | advice, 3 | args_get, 4 | args_sizes_get, 5 | clock_res_get, 6 | clock_time_get, 7 | clockid, 8 | subscription_clock, 9 | dircookie, 10 | environ_get, 11 | environ_sizes_get, 12 | errno, 13 | event, 14 | eventtype, 15 | fd_advise, 16 | fd_allocate, 17 | fd_close, 18 | fd_datasync, 19 | fd_fdstat_get, 20 | fd_fdstat_set_flags, 21 | fd_filestat_get, 22 | fd_filestat_set_size, 23 | fd_filestat_set_times, 24 | fd_prestat_dir_name, 25 | fd_read, 26 | fd_readdir, 27 | fd_seek, 28 | fd_sync, 29 | fd_tell, 30 | fd_write, 31 | fd, 32 | fdflags, 33 | fdstat, 34 | whence, 35 | filesize, 36 | filestat, 37 | filetype, 38 | fstflags, 39 | lookupflags, 40 | oflags, 41 | path_create_directory, 42 | path_filestat_get, 43 | path_link, 44 | path_open, 45 | path_rename, 46 | path_remove_directory, 47 | path_symlink, 48 | path_unlink_file, 49 | poll_oneoff, 50 | proc_exit, 51 | random_get, 52 | rights, 53 | } from "@assemblyscript/wasi-shim/assembly/bindings/wasi_snapshot_preview1"; 54 | 55 | type aisize = i32; 56 | 57 | /** 58 | * A WASI error 59 | */ 60 | export class WASIError extends Error { 61 | constructor(message: string = "") { 62 | super(message); 63 | this.name = "WASIError"; 64 | } 65 | } 66 | 67 | /** 68 | * Portable information about a file 69 | */ 70 | export class FileStat { 71 | file_type: filetype; 72 | file_size: filesize; 73 | access_time: f64; 74 | modification_time: f64; 75 | creation_time: f64; 76 | 77 | constructor(st_buf: usize) { 78 | this.file_type = load(st_buf, 16); 79 | this.file_size = load(st_buf, 24); 80 | this.access_time = (load(st_buf, 32) as f64) / 1e9; 81 | this.modification_time = (load(st_buf, 40) as f64) / 1e9; 82 | this.creation_time = (load(st_buf, 48) as f64) / 1e9; 83 | } 84 | } 85 | 86 | /** 87 | * A descriptor, that doesn't necessarily have to represent a file 88 | */ 89 | @final @unmanaged 90 | export class Descriptor { 91 | /** 92 | * An invalid file descriptor, that can represent an error 93 | */ 94 | @inline static get Invalid(): Descriptor { return new Descriptor(-1); }; 95 | 96 | /** 97 | * The standard input 98 | */ 99 | @inline static get Stdin(): Descriptor { return new Descriptor(0); }; 100 | 101 | /** 102 | * The standard output 103 | */ 104 | @inline static get Stdout(): Descriptor { return new Descriptor(1); }; 105 | 106 | /** 107 | * The standard error 108 | */ 109 | @inline static get Stderr(): Descriptor { return new Descriptor(2); }; 110 | 111 | /** 112 | * Build a new descriptor from a raw WASI file descriptor 113 | * @param rawfd a raw file descriptor 114 | */ 115 | constructor(rawfd: fd) { 116 | return changetype(rawfd); 117 | } 118 | 119 | @inline get rawfd(): fd { 120 | return changetype(this); 121 | } 122 | 123 | /** 124 | * Hint at how the data accessible via the descriptor will be used 125 | * @offset offset 126 | * @len length 127 | * @advice `advice.{NORMAL, SEQUENTIAL, RANDOM, WILLNEED, DONTNEED, NOREUSE}` 128 | * @returns `true` on success, `false` on error 129 | */ 130 | advise(offset: u64, len: u64, advice: advice): bool { 131 | return fd_advise(this.rawfd, offset, len, advice) === errno.SUCCESS; 132 | } 133 | 134 | /** 135 | * Preallocate data 136 | * @param offset where to start preallocating data in the file 137 | * @param len bytes to preallocate 138 | * @returns `true` on success, `false` on error 139 | */ 140 | allocate(offset: u64, len: u64): bool { 141 | return fd_allocate(this.rawfd, offset, len) === errno.SUCCESS; 142 | } 143 | 144 | /** 145 | * Wait for the data to be written 146 | * @returns `true` on success, `false` on error 147 | */ 148 | fdatasync(): bool { 149 | return fd_datasync(this.rawfd) === errno.SUCCESS; 150 | } 151 | 152 | /** 153 | * Wait for the data and metadata to be written 154 | * @returns `true` on success, `false` on error 155 | */ 156 | fsync(): bool { 157 | return fd_sync(this.rawfd) === errno.SUCCESS; 158 | } 159 | 160 | /** 161 | * Return the file type 162 | */ 163 | fileType(): filetype { 164 | // @ts-ignore 165 | let st_buf = memory.data(24); 166 | if (fd_fdstat_get(this.rawfd, changetype(st_buf)) !== errno.SUCCESS) { 167 | throw new WASIError("Unable to get the file type"); 168 | } 169 | return load(st_buf); 170 | } 171 | 172 | /** 173 | * Set WASI flags for that descriptor 174 | * @params flags: one or more of `fdflags.{APPEND, DSYNC, NONBLOCK, RSYNC, SYNC}` 175 | * @returns `true` on success, `false` on error 176 | */ 177 | setFlags(flags: fdflags): bool { 178 | return fd_fdstat_set_flags(this.rawfd, flags) === errno.SUCCESS; 179 | } 180 | 181 | /** 182 | * Retrieve information about a descriptor 183 | * @returns a `FileStat` object` 184 | */ 185 | stat(): FileStat { 186 | let st_buf = changetype(new ArrayBuffer(56)); 187 | if (fd_filestat_get(this.rawfd, changetype(st_buf)) !== errno.SUCCESS) { 188 | throw new WASIError("Unable to get the file information"); 189 | } 190 | return new FileStat(st_buf); 191 | } 192 | 193 | /** 194 | * Change the size of a file 195 | * @param size new size 196 | * @returns `true` on success, `false` on error 197 | */ 198 | ftruncate(size: u64 = 0): bool { 199 | return fd_filestat_set_size(this.rawfd, size) === errno.SUCCESS; 200 | } 201 | 202 | /** 203 | * Update the access time 204 | * @ts timestamp in seconds 205 | * @returns `true` on success, `false` on error 206 | */ 207 | fatime(ts: f64): bool { 208 | return ( 209 | fd_filestat_set_times(this.rawfd, (ts * 1e9) as u64, 0, fstflags.SET_ATIM) === 210 | errno.SUCCESS 211 | ); 212 | } 213 | 214 | /** 215 | * Update the modification time 216 | * @ts timestamp in seconds 217 | * @returns `true` on success, `false` on error 218 | */ 219 | fmtime(ts: f64): bool { 220 | return ( 221 | fd_filestat_set_times(this.rawfd, 0, (ts * 1e9) as u64, fstflags.SET_MTIM) === 222 | errno.SUCCESS 223 | ); 224 | } 225 | 226 | /** 227 | * Update both the access and the modification times 228 | * @atime timestamp in seconds 229 | * @mtime timestamp in seconds 230 | * @returns `true` on success, `false` on error 231 | */ 232 | futimes(atime: f64, mtime: f64): bool { 233 | return ( 234 | fd_filestat_set_times( 235 | this.rawfd, 236 | (atime * 1e9) as u64, 237 | (mtime * 1e9) as u64, 238 | fstflags.SET_ATIM | fstflags.SET_ATIM 239 | ) === errno.SUCCESS 240 | ); 241 | } 242 | 243 | /** 244 | * Update the timestamp of the object represented by the descriptor 245 | * @returns `true` on success, `false` on error 246 | */ 247 | touch(): bool { 248 | return ( 249 | fd_filestat_set_times( 250 | this.rawfd, 251 | 0, 252 | 0, 253 | fstflags.SET_ATIM_NOW | fstflags.SET_MTIM_NOW 254 | ) === errno.SUCCESS 255 | ); 256 | } 257 | 258 | /** 259 | * Return the directory associated to that descriptor 260 | */ 261 | dirName(): string { 262 | let path_max = 4096 as usize; 263 | // @ts-ignore 264 | let path_buf = heap.alloc(path_max); 265 | while (true) { 266 | let ret = fd_prestat_dir_name(this.rawfd, path_buf, path_max); 267 | if (ret === errno.NAMETOOLONG) { 268 | path_max *= 2; 269 | // @ts-ignore 270 | path_buf = heap.realloc(path_buf, path_max); 271 | continue; 272 | } 273 | let path = String.UTF8.decodeUnsafe(path_buf, path_max, true); 274 | // @ts-ignore 275 | heap.free(path_buf); 276 | return path; 277 | } 278 | } 279 | 280 | /** 281 | * Close a file descriptor 282 | */ 283 | close(): void { 284 | fd_close(this.rawfd); 285 | } 286 | 287 | /** 288 | * Write data to a file descriptor 289 | * @param data data 290 | */ 291 | write(data: u8[]): void { 292 | let data_buf_len = data.length; 293 | let data_buf_out = changetype(new ArrayBuffer(data_buf_len)); 294 | // @ts-ignore: cast 295 | let data_buf_in = changetype(data).dataStart; 296 | memory.copy(data_buf_out, data_buf_in, data_buf_len); 297 | let iov = memory.data(16); 298 | store(iov, data_buf_out, 0); 299 | store(iov, data_buf_len, sizeof()); 300 | let written_ptr = memory.data(8); 301 | fd_write(this.rawfd, iov, 1, written_ptr); 302 | } 303 | 304 | /** 305 | * Write a string to a file descriptor, after encoding it to UTF8 306 | * @param s string 307 | * @param newline `true` to add a newline after the string 308 | */ 309 | writeString(s: string, newline: bool = false): void { 310 | if (newline) { 311 | this.writeStringLn(s); 312 | return; 313 | } 314 | let s_utf8_buf = String.UTF8.encode(s); 315 | let s_utf8_len: usize = s_utf8_buf.byteLength; 316 | let iov = memory.data(16); 317 | store(iov, changetype(s_utf8_buf)); 318 | store(iov, s_utf8_len, sizeof()); 319 | 320 | let written_ptr = memory.data(8); 321 | fd_write(this.rawfd, iov, 1, written_ptr); 322 | } 323 | 324 | /** 325 | * Write a string to a file descriptor, after encoding it to UTF8, with a newline 326 | * @param s string 327 | */ 328 | writeStringLn(s: string): void { 329 | let s_utf8_buf = String.UTF8.encode(s); 330 | let s_utf8_len: usize = s_utf8_buf.byteLength; 331 | let iov = memory.data(32); 332 | store(iov, changetype(s_utf8_buf)); 333 | store(iov, s_utf8_len, sizeof()); 334 | let lf = memory.data(8); 335 | store(lf, 10); 336 | store(iov, lf, sizeof() * 2); 337 | store(iov, 1, sizeof() * 3); 338 | 339 | let written_ptr = memory.data(8); 340 | fd_write(this.rawfd, iov, 2, written_ptr); 341 | } 342 | 343 | /** 344 | * Read data from a file descriptor 345 | * @param data existing array to push data to 346 | * @param chunk_size chunk size (default: 4096) 347 | */ 348 | read( 349 | data: u8[] = [], 350 | chunk_size: usize = 4096 351 | ): u8[] | null { 352 | let data_partial_len = chunk_size; 353 | let data_partial = changetype(new ArrayBuffer(data_partial_len as aisize)); 354 | let iov = memory.data(16); 355 | store(iov, data_partial, 0); 356 | store(iov, data_partial_len, sizeof()); 357 | let read_ptr = memory.data(8); 358 | if (fd_read(this.rawfd, iov, 1, read_ptr) !== errno.SUCCESS) { 359 | return null; 360 | } 361 | let read = load(read_ptr); 362 | if (read > 0) { 363 | for (let i: usize = 0; i < read; i++) { 364 | data.push(load(data_partial + i)); 365 | } 366 | } 367 | if (read < 0) { 368 | return null; 369 | } 370 | return data; 371 | } 372 | 373 | /** 374 | * Read from a file descriptor until the end of the stream 375 | * @param data existing array to push data to 376 | * @param chunk_size chunk size (default: 4096) 377 | */ 378 | readAll( 379 | data: u8[] = [], 380 | chunk_size: usize = 4096 381 | ): u8[] | null { 382 | let data_partial_len = chunk_size; 383 | let data_partial = changetype(new ArrayBuffer(data_partial_len as aisize)); 384 | let iov = memory.data(16); 385 | store(iov, data_partial, 0); 386 | store(iov, data_partial_len, sizeof()); 387 | let read_ptr = memory.data(8); 388 | let read: usize = 0; 389 | let rawfd = this.rawfd; 390 | while (true) { 391 | if (fd_read(rawfd, iov, 1, read_ptr) !== errno.SUCCESS) { 392 | return null; 393 | } 394 | read = load(read_ptr); 395 | if (read <= 0) { 396 | break; 397 | } 398 | for (let i: usize = 0; i < read; i++) { 399 | data.push(load(data_partial + i)); 400 | } 401 | } 402 | if (read < 0) { 403 | return null; 404 | } 405 | return data; 406 | } 407 | 408 | /** 409 | * Read a line of text from a file descriptor 410 | */ 411 | readLine(): string | null { 412 | let byte = memory.data(1); 413 | let iov = memory.data(16); 414 | store(iov, byte, 0); 415 | store(iov, 1, sizeof()); 416 | let read_ptr = memory.data(8); 417 | let read: usize = 0; 418 | let rawfd = this.rawfd; 419 | let cr_seen = false; 420 | let line = new Array(); 421 | while (true) { 422 | if (fd_read(rawfd, iov, 1, read_ptr) !== errno.SUCCESS) { 423 | return null; 424 | } 425 | read = load(read_ptr); 426 | if (read <= 0) { 427 | return null; 428 | } 429 | let c = load(byte); 430 | if (c == 10) { 431 | break; 432 | } else if (c == 13 && !cr_seen) { 433 | cr_seen = true; 434 | } else if (cr_seen) { 435 | return null; 436 | } else { 437 | line.push(c); 438 | } 439 | } 440 | // @ts-ignore: cast 441 | return String.UTF8.decodeUnsafe(line.dataStart, line.length); 442 | } 443 | 444 | /** 445 | * Read as much data as possible from a file descriptor, convert it to a native string 446 | * @param chunk_size chunk size (default: 4096) 447 | */ 448 | readString(chunk_size: usize = 4096): string | null { 449 | let s_utf8 = this.readAll(); 450 | if (s_utf8 === null) { 451 | return null; 452 | } 453 | // @ts-ignore: cast 454 | return String.UTF8.decodeUnsafe(s_utf8.dataStart, s_utf8.length); 455 | } 456 | 457 | /** 458 | * Seek into a stream 459 | * @off offset 460 | * @w the position relative to which to set the offset of the file descriptor. 461 | */ 462 | seek(off: u64, w: whence): bool { 463 | let fodder = memory.data(8); 464 | let res = fd_seek(this.rawfd, off, w, fodder); 465 | 466 | return res === errno.SUCCESS; 467 | } 468 | 469 | /** 470 | * Return the current offset in the stream 471 | * @returns offset 472 | */ 473 | tell(): u64 { 474 | let buf_off = memory.data(8); 475 | let res = fd_tell(this.rawfd, buf_off); 476 | if (res !== errno.SUCCESS) { 477 | abort(); 478 | } 479 | return load(buf_off); 480 | } 481 | } 482 | 483 | /** 484 | * A class to access a filesystem 485 | */ 486 | export class FileSystem { 487 | /** 488 | * Open a path 489 | * @path path 490 | * @flags r, r+, w, wx, w+ or xw+ 491 | * @returns a descriptor 492 | */ 493 | static open(path: string, flags: string = "r"): Descriptor | null { 494 | let dirfd = this.dirfdForPath(path); 495 | let fd_lookup_flags = lookupflags.SYMLINK_FOLLOW; 496 | let fd_oflags: u16 = 0; 497 | let fd_rights: u64 = 0; 498 | if (flags == "r") { 499 | fd_rights = 500 | rights.FD_READ | rights.FD_SEEK | rights.FD_TELL | rights.FD_FILESTAT_GET | 501 | rights.FD_READDIR; 502 | } else if (flags == "r+") { 503 | fd_rights = 504 | rights.FD_WRITE | 505 | rights.FD_READ | rights.FD_SEEK | rights.FD_TELL | rights.FD_FILESTAT_GET | 506 | rights.PATH_CREATE_FILE; 507 | } else if (flags == "w") { 508 | fd_oflags = oflags.CREAT | oflags.TRUNC; 509 | fd_rights = 510 | rights.FD_WRITE | rights.FD_SEEK | rights.FD_TELL | rights.FD_FILESTAT_GET | 511 | rights.PATH_CREATE_FILE; 512 | } else if (flags == "wx") { 513 | fd_oflags = oflags.CREAT | oflags.TRUNC | oflags.EXCL; 514 | fd_rights = 515 | rights.FD_WRITE | rights.FD_SEEK | rights.FD_TELL | rights.FD_FILESTAT_GET | 516 | rights.PATH_CREATE_FILE; 517 | } else if (flags == "w+") { 518 | fd_oflags = oflags.CREAT | oflags.TRUNC; 519 | fd_rights = 520 | rights.FD_WRITE | 521 | rights.FD_READ | rights.FD_SEEK | rights.FD_TELL | rights.FD_FILESTAT_GET | 522 | rights.PATH_CREATE_FILE; 523 | } else if (flags == "xw+") { 524 | fd_oflags = oflags.CREAT | oflags.TRUNC | oflags.EXCL; 525 | fd_rights = 526 | rights.FD_WRITE | 527 | rights.FD_READ | rights.FD_SEEK | rights.FD_TELL | rights.FD_FILESTAT_GET | 528 | rights.PATH_CREATE_FILE; 529 | } else { 530 | return null; 531 | } 532 | let fd_rights_inherited = fd_rights; 533 | let fd_flags: fdflags = 0; 534 | let path_utf8_buf = String.UTF8.encode(path); 535 | let path_utf8_len: usize = path_utf8_buf.byteLength; 536 | let path_utf8 = changetype(path_utf8_buf); 537 | let fd_buf = memory.data(8); 538 | let res = path_open( 539 | dirfd as fd, 540 | fd_lookup_flags, 541 | path_utf8, path_utf8_len, 542 | fd_oflags, 543 | fd_rights, 544 | fd_rights_inherited, 545 | fd_flags, 546 | fd_buf 547 | ); 548 | if (res !== errno.SUCCESS) { 549 | return null; 550 | } 551 | let fd = load(fd_buf); 552 | return new Descriptor(fd); 553 | } 554 | 555 | /** 556 | * Create a new directory 557 | * @path path 558 | * @returns `true` on success, `false` on failure 559 | */ 560 | static mkdir(path: string): bool { 561 | let dirfd = this.dirfdForPath(path); 562 | 563 | let path_utf8_buf = String.UTF8.encode(path); 564 | let path_utf8_len: usize = path_utf8_buf.byteLength; 565 | let path_utf8 = changetype(path_utf8_buf); 566 | 567 | let res = path_create_directory(dirfd, path_utf8, path_utf8_len); 568 | 569 | return res === errno.SUCCESS; 570 | } 571 | 572 | /** 573 | * Check if a file exists at a given path 574 | * @path path 575 | * @returns `true` on success, `false` on failure 576 | */ 577 | static exists(path: string): bool { 578 | let dirfd = this.dirfdForPath(path); 579 | let path_utf8_buf = String.UTF8.encode(path); 580 | let path_utf8_len: usize = path_utf8_buf.byteLength; 581 | let path_utf8 = changetype(path_utf8_buf); 582 | let fd_lookup_flags = lookupflags.SYMLINK_FOLLOW; 583 | let st_buf = changetype(new ArrayBuffer(56)); 584 | let res = path_filestat_get( 585 | dirfd, 586 | fd_lookup_flags, 587 | path_utf8, path_utf8_len, 588 | changetype(st_buf) 589 | ); 590 | 591 | return res === errno.SUCCESS; 592 | } 593 | 594 | /** 595 | * Create a hard link 596 | * @old_path old path 597 | * @new_path new path 598 | * @returns `true` on success, `false` on failure 599 | */ 600 | static link(old_path: string, new_path: string): bool { 601 | let old_dirfd = this.dirfdForPath(old_path); 602 | 603 | let old_path_utf8_buf = String.UTF8.encode(old_path); 604 | let old_path_utf8_len: usize = old_path_utf8_buf.byteLength; 605 | let old_path_utf8 = changetype(old_path_utf8_buf); 606 | 607 | let new_dirfd = this.dirfdForPath(new_path); 608 | 609 | let new_path_utf8_buf = String.UTF8.encode(new_path); 610 | let new_path_utf8_len: usize = new_path_utf8_buf.byteLength; 611 | let new_path_utf8 = changetype(new_path_utf8_buf); 612 | 613 | let fd_lookup_flags = lookupflags.SYMLINK_FOLLOW; 614 | let res = path_link( 615 | old_dirfd, 616 | fd_lookup_flags, 617 | old_path_utf8, old_path_utf8_len, 618 | new_dirfd, 619 | new_path_utf8, new_path_utf8_len 620 | ); 621 | 622 | return res === errno.SUCCESS; 623 | } 624 | 625 | /** 626 | * Create a symbolic link 627 | * @old_path old path 628 | * @new_path new path 629 | * @returns `true` on success, `false` on failure 630 | */ 631 | static symlink(old_path: string, new_path: string): bool { 632 | let old_path_utf8_buf = String.UTF8.encode(old_path); 633 | let old_path_utf8_len: usize = old_path_utf8_buf.byteLength; 634 | let old_path_utf8 = changetype(old_path_utf8_buf); 635 | 636 | let new_dirfd = this.dirfdForPath(new_path); 637 | 638 | let new_path_utf8_buf = String.UTF8.encode(new_path); 639 | let new_path_utf8_len: usize = new_path_utf8_buf.byteLength; 640 | let new_path_utf8 = changetype(new_path_utf8_buf); 641 | 642 | 643 | let res = path_symlink( 644 | old_path_utf8, old_path_utf8_len, 645 | new_dirfd, 646 | new_path_utf8, new_path_utf8_len 647 | ); 648 | 649 | return res === errno.SUCCESS; 650 | } 651 | 652 | /** 653 | * Unlink a file 654 | * @path path 655 | * @returns `true` on success, `false` on failure 656 | */ 657 | static unlink(path: string): bool { 658 | let dirfd = this.dirfdForPath(path); 659 | 660 | let path_utf8_buf = String.UTF8.encode(path); 661 | let path_utf8_len: usize = path_utf8_buf.byteLength; 662 | let path_utf8 = changetype(path_utf8_buf); 663 | 664 | let res = path_unlink_file(dirfd, path_utf8, path_utf8_len); 665 | 666 | return res === errno.SUCCESS; 667 | } 668 | 669 | /** 670 | * Remove a directory 671 | * @path path 672 | * @returns `true` on success, `false` on failure 673 | */ 674 | static rmdir(path: string): bool { 675 | let dirfd = this.dirfdForPath(path); 676 | 677 | let path_utf8_buf = String.UTF8.encode(path); 678 | let path_utf8_len: usize = path_utf8_buf.byteLength; 679 | let path_utf8 = changetype(path_utf8_buf); 680 | 681 | let res = path_remove_directory(dirfd, path_utf8, path_utf8_len); 682 | 683 | return res === errno.SUCCESS; 684 | } 685 | 686 | /** 687 | * Retrieve information about a file 688 | * @path path 689 | * @returns a `FileStat` object 690 | */ 691 | static stat(path: string): FileStat { 692 | let dirfd = this.dirfdForPath(path); 693 | 694 | let path_utf8_buf = String.UTF8.encode(path); 695 | let path_utf8_len: usize = path_utf8_buf.byteLength; 696 | let path_utf8 = changetype(path_utf8_buf); 697 | 698 | let fd_lookup_flags = lookupflags.SYMLINK_FOLLOW; 699 | let st_buf = changetype(new ArrayBuffer(56)); 700 | if (path_filestat_get( 701 | dirfd, 702 | fd_lookup_flags, 703 | path_utf8, path_utf8_len, 704 | changetype(st_buf) 705 | ) !== errno.SUCCESS) { 706 | throw new WASIError("Unable to get the file information"); 707 | } 708 | return new FileStat(st_buf); 709 | } 710 | 711 | /** 712 | * Retrieve information about a file or a symbolic link 713 | * @path path 714 | * @returns a `FileStat` object 715 | */ 716 | static lstat(path: string): FileStat { 717 | let dirfd = this.dirfdForPath(path); 718 | 719 | let path_utf8_buf = String.UTF8.encode(path); 720 | let path_utf8_len: usize = path_utf8_buf.byteLength; 721 | let path_utf8 = changetype(path_utf8_buf); 722 | 723 | let fd_lookup_flags = 0; 724 | let st_buf = changetype(new ArrayBuffer(56)); 725 | if (path_filestat_get( 726 | dirfd, 727 | fd_lookup_flags, 728 | path_utf8, path_utf8_len, 729 | changetype(st_buf) 730 | ) !== errno.SUCCESS) { 731 | throw new WASIError("Unable to get the file information"); 732 | } 733 | return new FileStat(st_buf); 734 | } 735 | 736 | /** 737 | * Rename a file 738 | * @old_path old path 739 | * @new_path new path 740 | * @returns `true` on success, `false` on failure 741 | */ 742 | static rename(old_path: string, new_path: string): bool { 743 | let old_dirfd = this.dirfdForPath(old_path); 744 | 745 | let old_path_utf8_buf = String.UTF8.encode(old_path); 746 | let old_path_utf8_len: usize = old_path_utf8_buf.byteLength; 747 | let old_path_utf8 = changetype(old_path_utf8_buf); 748 | 749 | let new_dirfd = this.dirfdForPath(new_path); 750 | 751 | let new_path_utf8_buf = String.UTF8.encode(new_path); 752 | let new_path_utf8_len: usize = new_path_utf8_buf.byteLength; 753 | let new_path_utf8 = changetype(new_path_utf8_buf); 754 | 755 | let res = path_rename( 756 | old_dirfd, 757 | old_path_utf8, old_path_utf8_len, 758 | new_dirfd, 759 | new_path_utf8, new_path_utf8_len 760 | ); 761 | 762 | return res === errno.SUCCESS; 763 | } 764 | 765 | /** 766 | * Get the content of a directory 767 | * @param path the directory path 768 | * @returns An array of file names 769 | */ 770 | static readdir(path: string): Array | null { 771 | let fd = this.open(path, "r"); 772 | if (fd === null) { 773 | return null; 774 | } 775 | let out = new Array(); 776 | let buf_size = 4096; 777 | // @ts-ignore 778 | let buf = heap.alloc(buf_size); 779 | // @ts-ignore 780 | let buf_used_p = memory.data(8); 781 | let buf_used = 0; 782 | for (; ;) { 783 | if (fd_readdir(fd.rawfd, buf, buf_size, 0 as dircookie, buf_used_p) !== errno.SUCCESS) { 784 | fd.close(); 785 | } 786 | buf_used = load(buf_used_p); 787 | if (buf_used < buf_size) { 788 | break; 789 | } 790 | buf_size <<= 1; 791 | // @ts-ignore 792 | buf = heap.realloc(buf, buf_size); 793 | } 794 | let offset = 0; 795 | while (offset < buf_used) { 796 | offset += 16; 797 | let name_len = load(buf + offset); 798 | offset += 8; 799 | if (offset + name_len > buf_used) { 800 | return null; 801 | } 802 | let name = String.UTF8.decodeUnsafe(buf + offset, name_len); 803 | out.push(name); 804 | offset += name_len; 805 | } 806 | // @ts-ignore 807 | heap.free(buf); 808 | fd.close(); 809 | 810 | return out; 811 | } 812 | 813 | protected static dirfdForPath(path: string): fd { 814 | return 3; 815 | } 816 | } 817 | 818 | @global 819 | export class Console { 820 | /** 821 | * Write a string to the console 822 | * @param s string 823 | * @param newline `false` to avoid inserting a newline after the string 824 | */ 825 | static write(s: string, newline: bool = true): void { 826 | Descriptor.Stdout.writeString(s, newline); 827 | } 828 | 829 | /** 830 | * Read as much data as possible from the console, convert it to a native string 831 | */ 832 | static readAll(): string | null { 833 | return Descriptor.Stdin.readString(); 834 | } 835 | 836 | /** 837 | * Read a line of text from the console, convert it from UTF8 to a native string 838 | */ 839 | static readLine(): string | null { 840 | return Descriptor.Stdin.readLine(); 841 | } 842 | 843 | /** 844 | * Alias for `Console.write()` 845 | */ 846 | static log(s: string): void { 847 | this.write(s); 848 | } 849 | 850 | /** 851 | * Write an error to the console 852 | * @param s string 853 | * @param newline `false` to avoid inserting a newline after the string 854 | */ 855 | static error(s: string, newline: bool = true): void { 856 | Descriptor.Stderr.writeString(s, newline); 857 | } 858 | } 859 | 860 | export class Random { 861 | /** 862 | * Fill a buffer with random data 863 | * @param buffer An array buffer 864 | */ 865 | static randomFill(buffer: ArrayBuffer): void { 866 | let len = buffer.byteLength; 867 | let ptr = changetype(buffer); 868 | while (len > 0) { 869 | let chunk = min(len, 256); 870 | if (random_get(ptr, chunk) !== errno.SUCCESS) { 871 | abort(); 872 | } 873 | len -= chunk; 874 | ptr += chunk; 875 | } 876 | } 877 | 878 | /** 879 | * Return an array of random bytes 880 | * @param len length 881 | */ 882 | static randomBytes(len: usize): Uint8Array { 883 | let array = new Uint8Array(len as aisize); 884 | this.randomFill(array.buffer); 885 | return array; 886 | } 887 | } 888 | 889 | export class Date { 890 | /** 891 | * Return the current timestamp, as a number of milliseconds since the epoch 892 | */ 893 | static now(): f64 { 894 | let time_ptr = memory.data(8); 895 | clock_time_get(clockid.REALTIME, 1000000, time_ptr); 896 | let unix_ts = load(time_ptr); 897 | 898 | return (unix_ts as f64) / 1000000.0; 899 | } 900 | } 901 | 902 | export class Performance { 903 | static now(): f64 { 904 | let time_ptr = memory.data(8); 905 | clock_res_get(clockid.MONOTONIC, time_ptr); 906 | let res_ts = load(time_ptr); 907 | 908 | return res_ts as f64; 909 | } 910 | } 911 | 912 | export class Process { 913 | /** 914 | * Cleanly terminate the current process 915 | * @param status exit code 916 | */ 917 | @inline 918 | static exit(status: u32): void { 919 | proc_exit(status); 920 | } 921 | } 922 | 923 | export class EnvironEntry { 924 | constructor(readonly key: string, readonly value: string) { } 925 | } 926 | 927 | export class Environ { 928 | env: Array; 929 | 930 | constructor() { 931 | this.env = []; 932 | let count_and_size = memory.data(16); 933 | let ret = environ_sizes_get(count_and_size, count_and_size + 4); 934 | if (ret !== errno.SUCCESS) { 935 | abort(); 936 | } 937 | let count = load(count_and_size, 0); 938 | let size = load(count_and_size, sizeof()); 939 | let env_ptrs = changetype( 940 | new ArrayBuffer((count as aisize + 1) * sizeof()) 941 | ); 942 | let buf = changetype(new ArrayBuffer(size as aisize)); 943 | if (environ_get(env_ptrs, buf) !== errno.SUCCESS) { 944 | abort(); 945 | } 946 | for (let i: usize = 0; i < count; i++) { 947 | let env_ptr = load(env_ptrs + i * sizeof()); 948 | let env = StringUtils.fromCString(env_ptr); 949 | let eq = env.indexOf("="); 950 | this.env.push(new EnvironEntry(env.substring(0, eq), env.substring(eq + 1))); 951 | } 952 | } 953 | 954 | /** 955 | * Return all environment variables 956 | */ 957 | @inline 958 | static get all(): Array { 959 | return new Environ().env; 960 | } 961 | 962 | /** 963 | * Return all environment variables 964 | */ 965 | @inline 966 | all(): Array { 967 | return this.env; 968 | } 969 | 970 | /** 971 | * Return the value for an environment variable 972 | * @param key environment variable name 973 | */ 974 | get(key: string): string | null { 975 | let env = this.env; 976 | for (let i = 0, j = env.length; i < j; i++) { 977 | let pair = unchecked(env[i]); 978 | if (pair.key == key) { 979 | return pair.value; 980 | } 981 | } 982 | return null; 983 | } 984 | } 985 | 986 | export class CommandLine { 987 | args: string[]; 988 | 989 | constructor() { 990 | this.args = []; 991 | let count_and_size = memory.data(16); 992 | let ret = args_sizes_get(count_and_size, count_and_size + 4); 993 | if (ret !== errno.SUCCESS) { 994 | abort(); 995 | } 996 | let count = load(count_and_size, 0); 997 | let size = load(count_and_size, sizeof()); 998 | let env_ptrs = changetype( 999 | new ArrayBuffer((count as aisize + 1) * sizeof()) 1000 | ); 1001 | let buf = changetype(new ArrayBuffer(size as aisize)); 1002 | if (args_get(env_ptrs, buf) !== errno.SUCCESS) { 1003 | abort(); 1004 | } 1005 | for (let i: usize = 0; i < count; i++) { 1006 | let env_ptr = load(env_ptrs + i * sizeof()); 1007 | let arg = StringUtils.fromCString(env_ptr); 1008 | this.args.push(arg); 1009 | } 1010 | } 1011 | 1012 | /** 1013 | * Return all the command-line arguments 1014 | */ 1015 | @inline 1016 | static get all(): Array { 1017 | return new CommandLine().args; 1018 | } 1019 | 1020 | /** 1021 | * Return all the command-line arguments 1022 | */ 1023 | @inline 1024 | all(): Array { 1025 | return this.args; 1026 | } 1027 | 1028 | /** 1029 | * Return the i-th command-ine argument 1030 | * @param i index 1031 | */ 1032 | get(index: usize): string | null { 1033 | let args = this.args; 1034 | let args_len: usize = args[0].length; 1035 | if (index < args_len) { 1036 | return unchecked(args[index as aisize]); 1037 | } 1038 | return null; 1039 | } 1040 | } 1041 | 1042 | export class Time { 1043 | static NANOSECOND: i32 = 1; 1044 | static MILLISECOND: i32 = Time.NANOSECOND * 1000000; 1045 | static SECOND: i32 = Time.MILLISECOND * 1000; 1046 | 1047 | // This uses some hardcoded values to fix issues from: 1048 | // https://github.com/AssemblyScript/assemblyscript/issues/1116 1049 | static sleep(nanoseconds: i32): void { 1050 | // Create our subscription to the clock 1051 | let clockSub = changetype( 1052 | // @ts-ignore 1053 | memory.data(offsetof()) 1054 | ); 1055 | clockSub.userdata = 0; 1056 | clockSub.clock_id = clockid.REALTIME; 1057 | clockSub.timeout = nanoseconds; 1058 | clockSub.precision = 10000; 1059 | clockSub.type = eventtype.CLOCK; 1060 | clockSub.flags = 0; 1061 | // We want this to be relative, no flags / subclockflag 1062 | 1063 | // Create our output event 1064 | // @ts-ignore 1065 | let clockEvent = memory.data(offsetof() + 3); 1066 | 1067 | // Create a buffer for our number of sleep events 1068 | // To inspect how many events happened, one would then do load(neventsBuffer) 1069 | // @ts-ignore 1070 | let neventsBuffer = memory.data(4); 1071 | 1072 | // Poll the subscription 1073 | poll_oneoff( 1074 | changetype(clockSub), // Pointer to the clock subscription 1075 | clockEvent, // Pointer to the clock event 1076 | 1, // Number of events to wait for 1077 | neventsBuffer // Buffer where events should be stored. 1078 | ); 1079 | } 1080 | } 1081 | 1082 | class StringUtils { 1083 | /** 1084 | * Returns a native string from a zero-terminated C string 1085 | * @param cstring 1086 | * @returns native string 1087 | */ 1088 | @inline 1089 | static fromCString(cstring: usize): string { 1090 | let size = 0; 1091 | while (load(cstring + size) !== 0) { 1092 | size++; 1093 | } 1094 | return String.UTF8.decodeUnsafe(cstring, size); 1095 | } 1096 | } 1097 | -------------------------------------------------------------------------------- /REFERENCE_API_DOCS.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | **[as-wasi](#readmemd)** 5 | 6 | > Globals 7 | 8 | # as-wasi 9 | 10 | ## Index 11 | 12 | ### Classes 13 | 14 | * [CommandLine](#classescommandlinemd) 15 | * [Console](#classesconsolemd) 16 | * [Date](#classesdatemd) 17 | * [Descriptor](#classesdescriptormd) 18 | * [Environ](#classesenvironmd) 19 | * [EnvironEntry](#classesenvironentrymd) 20 | * [FileStat](#classesfilestatmd) 21 | * [FileSystem](#classesfilesystemmd) 22 | * [Performance](#classesperformancemd) 23 | * [Process](#classesprocessmd) 24 | * [Random](#classesrandommd) 25 | * [StringUtils](#classesstringutilsmd) 26 | * [Time](#classestimemd) 27 | * [WASIError](#classeswasierrormd) 28 | 29 | ### Type aliases 30 | 31 | * [aisize](#aisize) 32 | 33 | ### Functions 34 | 35 | * [wasi\_abort](#wasi_abort) 36 | 37 | ## Type aliases 38 | 39 | ### aisize 40 | 41 | Ƭ **aisize**: i32 42 | 43 | *Defined in [assembly/as-wasi.ts:55](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L55)* 44 | 45 | ## Functions 46 | 47 | ### wasi\_abort 48 | 49 | ▸ **wasi_abort**(`message?`: string, `fileName?`: string, `lineNumber?`: u32, `columnNumber?`: u32): void 50 | 51 | *Defined in [assembly/as-wasi.ts:1102](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1102)* 52 | 53 | #### Parameters: 54 | 55 | Name | Type | Default value | 56 | ------ | ------ | ------ | 57 | `message` | string | "" | 58 | `fileName` | string | "" | 59 | `lineNumber` | u32 | 0 | 60 | `columnNumber` | u32 | 0 | 61 | 62 | **Returns:** void 63 | 64 | # Classes 65 | 66 | 67 | 68 | 69 | **[as-wasi](#readmemd)** 70 | 71 | > [Globals](#readmemd) / CommandLine 72 | 73 | ## Class: CommandLine 74 | 75 | ### Hierarchy 76 | 77 | * **CommandLine** 78 | 79 | ### Index 80 | 81 | #### Constructors 82 | 83 | * [constructor](#constructor) 84 | 85 | #### Properties 86 | 87 | * [args](#args) 88 | 89 | #### Accessors 90 | 91 | * [all](#all) 92 | 93 | #### Methods 94 | 95 | * [all](#all) 96 | * [get](#get) 97 | 98 | ### Constructors 99 | 100 | #### constructor 101 | 102 | \+ **new CommandLine**(): [CommandLine](#classescommandlinemd) 103 | 104 | *Defined in [assembly/as-wasi.ts:989](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L989)* 105 | 106 | **Returns:** [CommandLine](#classescommandlinemd) 107 | 108 | ### Properties 109 | 110 | #### args 111 | 112 | • **args**: string[] 113 | 114 | *Defined in [assembly/as-wasi.ts:989](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L989)* 115 | 116 | ### Accessors 117 | 118 | #### all 119 | 120 | • `Static`get **all**(): Array\ 121 | 122 | *Defined in [assembly/as-wasi.ts:1018](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1018)* 123 | 124 | Return all the command-line arguments 125 | 126 | **Returns:** Array\ 127 | 128 | ### Methods 129 | 130 | #### all 131 | 132 | ▸ **all**(): Array\ 133 | 134 | *Defined in [assembly/as-wasi.ts:1026](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1026)* 135 | 136 | Return all the command-line arguments 137 | 138 | **Returns:** Array\ 139 | 140 | ___ 141 | 142 | #### get 143 | 144 | ▸ **get**(`index`: usize): string \| null 145 | 146 | *Defined in [assembly/as-wasi.ts:1034](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1034)* 147 | 148 | Return the i-th command-ine argument 149 | 150 | ##### Parameters: 151 | 152 | Name | Type | 153 | ------ | ------ | 154 | `index` | usize | 155 | 156 | **Returns:** string \| null 157 | 158 | 159 | 160 | 161 | **[as-wasi](#readmemd)** 162 | 163 | > [Globals](#readmemd) / Console 164 | 165 | ## Class: Console 166 | 167 | ### Hierarchy 168 | 169 | * **Console** 170 | 171 | ### Index 172 | 173 | #### Methods 174 | 175 | * [error](#error) 176 | * [log](#log) 177 | * [readAll](#readall) 178 | * [readLine](#readline) 179 | * [write](#write) 180 | 181 | ### Methods 182 | 183 | #### error 184 | 185 | ▸ `Static`**error**(`s`: string, `newline?`: bool): void 186 | 187 | *Defined in [assembly/as-wasi.ts:857](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L857)* 188 | 189 | Write an error to the console 190 | 191 | ##### Parameters: 192 | 193 | Name | Type | Default value | Description | 194 | ------ | ------ | ------ | ------ | 195 | `s` | string | - | string | 196 | `newline` | bool | true | `false` to avoid inserting a newline after the string | 197 | 198 | **Returns:** void 199 | 200 | ___ 201 | 202 | #### log 203 | 204 | ▸ `Static`**log**(`s`: string): void 205 | 206 | *Defined in [assembly/as-wasi.ts:848](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L848)* 207 | 208 | Alias for `Console.write()` 209 | 210 | ##### Parameters: 211 | 212 | Name | Type | 213 | ------ | ------ | 214 | `s` | string | 215 | 216 | **Returns:** void 217 | 218 | ___ 219 | 220 | #### readAll 221 | 222 | ▸ `Static`**readAll**(): string \| null 223 | 224 | *Defined in [assembly/as-wasi.ts:834](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L834)* 225 | 226 | Read an UTF8 string from the console, convert it to a native string 227 | 228 | **Returns:** string \| null 229 | 230 | ___ 231 | 232 | #### readLine 233 | 234 | ▸ `Static`**readLine**(): string \| null 235 | 236 | *Defined in [assembly/as-wasi.ts:841](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L841)* 237 | 238 | Read a line of text from the console, convert it from UTF8 to a native string 239 | 240 | **Returns:** string \| null 241 | 242 | ___ 243 | 244 | #### write 245 | 246 | ▸ `Static`**write**(`s`: string, `newline?`: bool): void 247 | 248 | *Defined in [assembly/as-wasi.ts:827](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L827)* 249 | 250 | Write a string to the console 251 | 252 | ##### Parameters: 253 | 254 | Name | Type | Default value | Description | 255 | ------ | ------ | ------ | ------ | 256 | `s` | string | - | string | 257 | `newline` | bool | true | `false` to avoid inserting a newline after the string | 258 | 259 | **Returns:** void 260 | 261 | 262 | 263 | 264 | **[as-wasi](#readmemd)** 265 | 266 | > [Globals](#readmemd) / Date 267 | 268 | ## Class: Date 269 | 270 | ### Hierarchy 271 | 272 | * **Date** 273 | 274 | ### Index 275 | 276 | #### Methods 277 | 278 | * [now](#now) 279 | 280 | ### Methods 281 | 282 | #### now 283 | 284 | ▸ `Static`**now**(): f64 285 | 286 | *Defined in [assembly/as-wasi.ts:895](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L895)* 287 | 288 | Return the current timestamp, as a number of milliseconds since the epoch 289 | 290 | **Returns:** f64 291 | 292 | 293 | 294 | 295 | **[as-wasi](#readmemd)** 296 | 297 | > [Globals](#readmemd) / Descriptor 298 | 299 | ## Class: Descriptor 300 | 301 | A descriptor, that doesn't necessarily have to represent a file 302 | 303 | ### Hierarchy 304 | 305 | * **Descriptor** 306 | 307 | ### Index 308 | 309 | #### Constructors 310 | 311 | * [constructor](#constructor) 312 | 313 | #### Accessors 314 | 315 | * [rawfd](#rawfd) 316 | * [Invalid](#invalid) 317 | * [Stderr](#stderr) 318 | * [Stdin](#stdin) 319 | * [Stdout](#stdout) 320 | 321 | #### Methods 322 | 323 | * [advise](#advise) 324 | * [allocate](#allocate) 325 | * [close](#close) 326 | * [dirName](#dirname) 327 | * [fatime](#fatime) 328 | * [fdatasync](#fdatasync) 329 | * [fileType](#filetype) 330 | * [fmtime](#fmtime) 331 | * [fsync](#fsync) 332 | * [ftruncate](#ftruncate) 333 | * [futimes](#futimes) 334 | * [read](#read) 335 | * [readAll](#readall) 336 | * [readLine](#readline) 337 | * [readString](#readstring) 338 | * [seek](#seek) 339 | * [setFlags](#setflags) 340 | * [stat](#stat) 341 | * [tell](#tell) 342 | * [touch](#touch) 343 | * [write](#write) 344 | * [writeString](#writestring) 345 | * [writeStringLn](#writestringln) 346 | 347 | ### Constructors 348 | 349 | #### constructor 350 | 351 | \+ **new Descriptor**(`rawfd`: fd): [Descriptor](#classesdescriptormd) 352 | 353 | *Defined in [assembly/as-wasi.ts:109](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L109)* 354 | 355 | Build a new descriptor from a raw WASI file descriptor 356 | 357 | ##### Parameters: 358 | 359 | Name | Type | Description | 360 | ------ | ------ | ------ | 361 | `rawfd` | fd | a raw file descriptor | 362 | 363 | **Returns:** [Descriptor](#classesdescriptormd) 364 | 365 | ### Accessors 366 | 367 | #### rawfd 368 | 369 | • get **rawfd**(): fd 370 | 371 | *Defined in [assembly/as-wasi.ts:119](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L119)* 372 | 373 | **Returns:** fd 374 | 375 | ___ 376 | 377 | #### Invalid 378 | 379 | • `Static`get **Invalid**(): [Descriptor](#classesdescriptormd) 380 | 381 | *Defined in [assembly/as-wasi.ts:94](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L94)* 382 | 383 | An invalid file descriptor, that can represent an error 384 | 385 | **Returns:** [Descriptor](#classesdescriptormd) 386 | 387 | ___ 388 | 389 | #### Stderr 390 | 391 | • `Static`get **Stderr**(): [Descriptor](#classesdescriptormd) 392 | 393 | *Defined in [assembly/as-wasi.ts:109](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L109)* 394 | 395 | The standard error 396 | 397 | **Returns:** [Descriptor](#classesdescriptormd) 398 | 399 | ___ 400 | 401 | #### Stdin 402 | 403 | • `Static`get **Stdin**(): [Descriptor](#classesdescriptormd) 404 | 405 | *Defined in [assembly/as-wasi.ts:99](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L99)* 406 | 407 | The standard input 408 | 409 | **Returns:** [Descriptor](#classesdescriptormd) 410 | 411 | ___ 412 | 413 | #### Stdout 414 | 415 | • `Static`get **Stdout**(): [Descriptor](#classesdescriptormd) 416 | 417 | *Defined in [assembly/as-wasi.ts:104](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L104)* 418 | 419 | The standard output 420 | 421 | **Returns:** [Descriptor](#classesdescriptormd) 422 | 423 | ### Methods 424 | 425 | #### advise 426 | 427 | ▸ **advise**(`offset`: u64, `len`: u64, `advice`: advice): bool 428 | 429 | *Defined in [assembly/as-wasi.ts:130](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L130)* 430 | 431 | Hint at how the data accessible via the descriptor will be used 432 | 433 | **`offset`** offset 434 | 435 | **`len`** length 436 | 437 | **`advice`** `advice.{NORMAL, SEQUENTIAL, RANDOM, WILLNEED, DONTNEED, NOREUSE}` 438 | 439 | ##### Parameters: 440 | 441 | Name | Type | 442 | ------ | ------ | 443 | `offset` | u64 | 444 | `len` | u64 | 445 | `advice` | advice | 446 | 447 | **Returns:** bool 448 | 449 | `true` on success, `false` on error 450 | 451 | ___ 452 | 453 | #### allocate 454 | 455 | ▸ **allocate**(`offset`: u64, `len`: u64): bool 456 | 457 | *Defined in [assembly/as-wasi.ts:140](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L140)* 458 | 459 | Preallocate data 460 | 461 | ##### Parameters: 462 | 463 | Name | Type | Description | 464 | ------ | ------ | ------ | 465 | `offset` | u64 | where to start preallocating data in the file | 466 | `len` | u64 | bytes to preallocate | 467 | 468 | **Returns:** bool 469 | 470 | `true` on success, `false` on error 471 | 472 | ___ 473 | 474 | #### close 475 | 476 | ▸ **close**(): void 477 | 478 | *Defined in [assembly/as-wasi.ts:283](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L283)* 479 | 480 | Close a file descriptor 481 | 482 | **Returns:** void 483 | 484 | ___ 485 | 486 | #### dirName 487 | 488 | ▸ **dirName**(): string 489 | 490 | *Defined in [assembly/as-wasi.ts:261](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L261)* 491 | 492 | Return the directory associated to that descriptor 493 | 494 | **Returns:** string 495 | 496 | ___ 497 | 498 | #### fatime 499 | 500 | ▸ **fatime**(`ts`: f64): bool 501 | 502 | *Defined in [assembly/as-wasi.ts:207](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L207)* 503 | 504 | Update the access time 505 | 506 | **`ts`** timestamp in seconds 507 | 508 | ##### Parameters: 509 | 510 | Name | Type | 511 | ------ | ------ | 512 | `ts` | f64 | 513 | 514 | **Returns:** bool 515 | 516 | `true` on success, `false` on error 517 | 518 | ___ 519 | 520 | #### fdatasync 521 | 522 | ▸ **fdatasync**(): bool 523 | 524 | *Defined in [assembly/as-wasi.ts:148](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L148)* 525 | 526 | Wait for the data to be written 527 | 528 | **Returns:** bool 529 | 530 | `true` on success, `false` on error 531 | 532 | ___ 533 | 534 | #### fileType 535 | 536 | ▸ **fileType**(): filetype 537 | 538 | *Defined in [assembly/as-wasi.ts:163](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L163)* 539 | 540 | Return the file type 541 | 542 | **Returns:** filetype 543 | 544 | ___ 545 | 546 | #### fmtime 547 | 548 | ▸ **fmtime**(`ts`: f64): bool 549 | 550 | *Defined in [assembly/as-wasi.ts:219](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L219)* 551 | 552 | Update the modification time 553 | 554 | **`ts`** timestamp in seconds 555 | 556 | ##### Parameters: 557 | 558 | Name | Type | 559 | ------ | ------ | 560 | `ts` | f64 | 561 | 562 | **Returns:** bool 563 | 564 | `true` on success, `false` on error 565 | 566 | ___ 567 | 568 | #### fsync 569 | 570 | ▸ **fsync**(): bool 571 | 572 | *Defined in [assembly/as-wasi.ts:156](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L156)* 573 | 574 | Wait for the data and metadata to be written 575 | 576 | **Returns:** bool 577 | 578 | `true` on success, `false` on error 579 | 580 | ___ 581 | 582 | #### ftruncate 583 | 584 | ▸ **ftruncate**(`size?`: u64): bool 585 | 586 | *Defined in [assembly/as-wasi.ts:198](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L198)* 587 | 588 | Change the size of a file 589 | 590 | ##### Parameters: 591 | 592 | Name | Type | Default value | Description | 593 | ------ | ------ | ------ | ------ | 594 | `size` | u64 | 0 | new size | 595 | 596 | **Returns:** bool 597 | 598 | `true` on success, `false` on error 599 | 600 | ___ 601 | 602 | #### futimes 603 | 604 | ▸ **futimes**(`atime`: f64, `mtime`: f64): bool 605 | 606 | *Defined in [assembly/as-wasi.ts:232](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L232)* 607 | 608 | Update both the access and the modification times 609 | 610 | **`atime`** timestamp in seconds 611 | 612 | **`mtime`** timestamp in seconds 613 | 614 | ##### Parameters: 615 | 616 | Name | Type | 617 | ------ | ------ | 618 | `atime` | f64 | 619 | `mtime` | f64 | 620 | 621 | **Returns:** bool 622 | 623 | `true` on success, `false` on error 624 | 625 | ___ 626 | 627 | #### read 628 | 629 | ▸ **read**(`data?`: u8[], `chunk_size?`: usize): u8[] \| null 630 | 631 | *Defined in [assembly/as-wasi.ts:348](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L348)* 632 | 633 | Read data from a file descriptor 634 | 635 | ##### Parameters: 636 | 637 | Name | Type | Default value | Description | 638 | ------ | ------ | ------ | ------ | 639 | `data` | u8[] | [] | existing array to push data to | 640 | `chunk_size` | usize | 4096 | chunk size (default: 4096) | 641 | 642 | **Returns:** u8[] \| null 643 | 644 | ___ 645 | 646 | #### readAll 647 | 648 | ▸ **readAll**(`data?`: u8[], `chunk_size?`: usize): u8[] \| null 649 | 650 | *Defined in [assembly/as-wasi.ts:378](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L378)* 651 | 652 | Read from a file descriptor until the end of the stream 653 | 654 | ##### Parameters: 655 | 656 | Name | Type | Default value | Description | 657 | ------ | ------ | ------ | ------ | 658 | `data` | u8[] | [] | existing array to push data to | 659 | `chunk_size` | usize | 4096 | chunk size (default: 4096) | 660 | 661 | **Returns:** u8[] \| null 662 | 663 | ___ 664 | 665 | #### readLine 666 | 667 | ▸ **readLine**(): string \| null 668 | 669 | *Defined in [assembly/as-wasi.ts:411](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L411)* 670 | 671 | Read a line of text from a file descriptor 672 | 673 | **Returns:** string \| null 674 | 675 | ___ 676 | 677 | #### readString 678 | 679 | ▸ **readString**(`chunk_size?`: usize): string \| null 680 | 681 | *Defined in [assembly/as-wasi.ts:450](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L450)* 682 | 683 | Read an UTF8 string from a file descriptor, convert it to a native string 684 | 685 | ##### Parameters: 686 | 687 | Name | Type | Default value | Description | 688 | ------ | ------ | ------ | ------ | 689 | `chunk_size` | usize | 4096 | chunk size (default: 4096) | 690 | 691 | **Returns:** string \| null 692 | 693 | ___ 694 | 695 | #### seek 696 | 697 | ▸ **seek**(`off`: u64, `w`: whence): bool 698 | 699 | *Defined in [assembly/as-wasi.ts:464](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L464)* 700 | 701 | Seek into a stream 702 | 703 | **`off`** offset 704 | 705 | **`w`** the position relative to which to set the offset of the file descriptor. 706 | 707 | ##### Parameters: 708 | 709 | Name | Type | 710 | ------ | ------ | 711 | `off` | u64 | 712 | `w` | whence | 713 | 714 | **Returns:** bool 715 | 716 | ___ 717 | 718 | #### setFlags 719 | 720 | ▸ **setFlags**(`flags`: fdflags): bool 721 | 722 | *Defined in [assembly/as-wasi.ts:177](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L177)* 723 | 724 | Set WASI flags for that descriptor 725 | 726 | **`params`** flags: one or more of `fdflags.{APPEND, DSYNC, NONBLOCK, RSYNC, SYNC}` 727 | 728 | ##### Parameters: 729 | 730 | Name | Type | 731 | ------ | ------ | 732 | `flags` | fdflags | 733 | 734 | **Returns:** bool 735 | 736 | `true` on success, `false` on error 737 | 738 | ___ 739 | 740 | #### stat 741 | 742 | ▸ **stat**(): [FileStat](#classesfilestatmd) 743 | 744 | *Defined in [assembly/as-wasi.ts:185](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L185)* 745 | 746 | Retrieve information about a descriptor 747 | 748 | **Returns:** [FileStat](#classesfilestatmd) 749 | 750 | a `FileStat` object` 751 | 752 | ___ 753 | 754 | #### tell 755 | 756 | ▸ **tell**(): u64 757 | 758 | *Defined in [assembly/as-wasi.ts:475](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L475)* 759 | 760 | Return the current offset in the stream 761 | 762 | **Returns:** u64 763 | 764 | offset 765 | 766 | ___ 767 | 768 | #### touch 769 | 770 | ▸ **touch**(): bool 771 | 772 | *Defined in [assembly/as-wasi.ts:247](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L247)* 773 | 774 | Update the timestamp of the object represented by the descriptor 775 | 776 | **Returns:** bool 777 | 778 | `true` on success, `false` on error 779 | 780 | ___ 781 | 782 | #### write 783 | 784 | ▸ **write**(`data`: u8[]): void 785 | 786 | *Defined in [assembly/as-wasi.ts:291](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L291)* 787 | 788 | Write data to a file descriptor 789 | 790 | ##### Parameters: 791 | 792 | Name | Type | Description | 793 | ------ | ------ | ------ | 794 | `data` | u8[] | data | 795 | 796 | **Returns:** void 797 | 798 | ___ 799 | 800 | #### writeString 801 | 802 | ▸ **writeString**(`s`: string, `newline?`: bool): void 803 | 804 | *Defined in [assembly/as-wasi.ts:309](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L309)* 805 | 806 | Write a string to a file descriptor, after encoding it to UTF8 807 | 808 | ##### Parameters: 809 | 810 | Name | Type | Default value | Description | 811 | ------ | ------ | ------ | ------ | 812 | `s` | string | - | string | 813 | `newline` | bool | false | `true` to add a newline after the string | 814 | 815 | **Returns:** void 816 | 817 | ___ 818 | 819 | #### writeStringLn 820 | 821 | ▸ **writeStringLn**(`s`: string): void 822 | 823 | *Defined in [assembly/as-wasi.ts:328](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L328)* 824 | 825 | Write a string to a file descriptor, after encoding it to UTF8, with a newline 826 | 827 | ##### Parameters: 828 | 829 | Name | Type | Description | 830 | ------ | ------ | ------ | 831 | `s` | string | string | 832 | 833 | **Returns:** void 834 | 835 | 836 | 837 | 838 | **[as-wasi](#readmemd)** 839 | 840 | > [Globals](#readmemd) / Environ 841 | 842 | ## Class: Environ 843 | 844 | ### Hierarchy 845 | 846 | * **Environ** 847 | 848 | ### Index 849 | 850 | #### Constructors 851 | 852 | * [constructor](#constructor) 853 | 854 | #### Properties 855 | 856 | * [env](#env) 857 | 858 | #### Accessors 859 | 860 | * [all](#all) 861 | 862 | #### Methods 863 | 864 | * [all](#all) 865 | * [get](#get) 866 | 867 | ### Constructors 868 | 869 | #### constructor 870 | 871 | \+ **new Environ**(): [Environ](#classesenvironmd) 872 | 873 | *Defined in [assembly/as-wasi.ts:930](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L930)* 874 | 875 | **Returns:** [Environ](#classesenvironmd) 876 | 877 | ### Properties 878 | 879 | #### env 880 | 881 | • **env**: Array\<[EnvironEntry](#classesenvironentrymd)> 882 | 883 | *Defined in [assembly/as-wasi.ts:930](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L930)* 884 | 885 | ### Accessors 886 | 887 | #### all 888 | 889 | • `Static`get **all**(): Array\<[EnvironEntry](#classesenvironentrymd)> 890 | 891 | *Defined in [assembly/as-wasi.ts:960](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L960)* 892 | 893 | Return all environment variables 894 | 895 | **Returns:** Array\<[EnvironEntry](#classesenvironentrymd)> 896 | 897 | ### Methods 898 | 899 | #### all 900 | 901 | ▸ **all**(): Array\<[EnvironEntry](#classesenvironentrymd)> 902 | 903 | *Defined in [assembly/as-wasi.ts:968](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L968)* 904 | 905 | Return all environment variables 906 | 907 | **Returns:** Array\<[EnvironEntry](#classesenvironentrymd)> 908 | 909 | ___ 910 | 911 | #### get 912 | 913 | ▸ **get**(`key`: string): string \| null 914 | 915 | *Defined in [assembly/as-wasi.ts:976](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L976)* 916 | 917 | Return the value for an environment variable 918 | 919 | ##### Parameters: 920 | 921 | Name | Type | Description | 922 | ------ | ------ | ------ | 923 | `key` | string | environment variable name | 924 | 925 | **Returns:** string \| null 926 | 927 | 928 | 929 | 930 | **[as-wasi](#readmemd)** 931 | 932 | > [Globals](#readmemd) / EnvironEntry 933 | 934 | ## Class: EnvironEntry 935 | 936 | ### Hierarchy 937 | 938 | * **EnvironEntry** 939 | 940 | ### Index 941 | 942 | #### Constructors 943 | 944 | * [constructor](#constructor) 945 | 946 | #### Properties 947 | 948 | * [key](#key) 949 | * [value](#value) 950 | 951 | ### Constructors 952 | 953 | #### constructor 954 | 955 | \+ **new EnvironEntry**(`key`: string, `value`: string): [EnvironEntry](#classesenvironentrymd) 956 | 957 | *Defined in [assembly/as-wasi.ts:925](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L925)* 958 | 959 | ##### Parameters: 960 | 961 | Name | Type | 962 | ------ | ------ | 963 | `key` | string | 964 | `value` | string | 965 | 966 | **Returns:** [EnvironEntry](#classesenvironentrymd) 967 | 968 | ### Properties 969 | 970 | #### key 971 | 972 | • `Readonly` **key**: string 973 | 974 | *Defined in [assembly/as-wasi.ts:926](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L926)* 975 | 976 | ___ 977 | 978 | #### value 979 | 980 | • `Readonly` **value**: string 981 | 982 | *Defined in [assembly/as-wasi.ts:926](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L926)* 983 | 984 | 985 | 986 | 987 | **[as-wasi](#readmemd)** 988 | 989 | > [Globals](#readmemd) / FileStat 990 | 991 | ## Class: FileStat 992 | 993 | Portable information about a file 994 | 995 | ### Hierarchy 996 | 997 | * **FileStat** 998 | 999 | ### Index 1000 | 1001 | #### Constructors 1002 | 1003 | * [constructor](#constructor) 1004 | 1005 | #### Properties 1006 | 1007 | * [access\_time](#access_time) 1008 | * [creation\_time](#creation_time) 1009 | * [file\_size](#file_size) 1010 | * [file\_type](#file_type) 1011 | * [modification\_time](#modification_time) 1012 | 1013 | ### Constructors 1014 | 1015 | #### constructor 1016 | 1017 | \+ **new FileStat**(`st_buf`: usize): [FileStat](#classesfilestatmd) 1018 | 1019 | *Defined in [assembly/as-wasi.ts:75](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L75)* 1020 | 1021 | ##### Parameters: 1022 | 1023 | Name | Type | 1024 | ------ | ------ | 1025 | `st_buf` | usize | 1026 | 1027 | **Returns:** [FileStat](#classesfilestatmd) 1028 | 1029 | ### Properties 1030 | 1031 | #### access\_time 1032 | 1033 | • **access\_time**: f64 1034 | 1035 | *Defined in [assembly/as-wasi.ts:73](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L73)* 1036 | 1037 | ___ 1038 | 1039 | #### creation\_time 1040 | 1041 | • **creation\_time**: f64 1042 | 1043 | *Defined in [assembly/as-wasi.ts:75](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L75)* 1044 | 1045 | ___ 1046 | 1047 | #### file\_size 1048 | 1049 | • **file\_size**: filesize 1050 | 1051 | *Defined in [assembly/as-wasi.ts:72](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L72)* 1052 | 1053 | ___ 1054 | 1055 | #### file\_type 1056 | 1057 | • **file\_type**: filetype 1058 | 1059 | *Defined in [assembly/as-wasi.ts:71](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L71)* 1060 | 1061 | ___ 1062 | 1063 | #### modification\_time 1064 | 1065 | • **modification\_time**: f64 1066 | 1067 | *Defined in [assembly/as-wasi.ts:74](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L74)* 1068 | 1069 | 1070 | 1071 | 1072 | **[as-wasi](#readmemd)** 1073 | 1074 | > [Globals](#readmemd) / FileSystem 1075 | 1076 | ## Class: FileSystem 1077 | 1078 | A class to access a filesystem 1079 | 1080 | ### Hierarchy 1081 | 1082 | * **FileSystem** 1083 | 1084 | ### Index 1085 | 1086 | #### Methods 1087 | 1088 | * [dirfdForPath](#dirfdforpath) 1089 | * [exists](#exists) 1090 | * [link](#link) 1091 | * [lstat](#lstat) 1092 | * [mkdir](#mkdir) 1093 | * [open](#open) 1094 | * [readdir](#readdir) 1095 | * [rename](#rename) 1096 | * [rmdir](#rmdir) 1097 | * [stat](#stat) 1098 | * [symlink](#symlink) 1099 | * [unlink](#unlink) 1100 | 1101 | ### Methods 1102 | 1103 | #### dirfdForPath 1104 | 1105 | ▸ `Static` `Protected`**dirfdForPath**(`path`: string): fd 1106 | 1107 | *Defined in [assembly/as-wasi.ts:815](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L815)* 1108 | 1109 | ##### Parameters: 1110 | 1111 | Name | Type | 1112 | ------ | ------ | 1113 | `path` | string | 1114 | 1115 | **Returns:** fd 1116 | 1117 | ___ 1118 | 1119 | #### exists 1120 | 1121 | ▸ `Static`**exists**(`path`: string): bool 1122 | 1123 | *Defined in [assembly/as-wasi.ts:579](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L579)* 1124 | 1125 | Check if a file exists at a given path 1126 | 1127 | **`path`** path 1128 | 1129 | ##### Parameters: 1130 | 1131 | Name | Type | 1132 | ------ | ------ | 1133 | `path` | string | 1134 | 1135 | **Returns:** bool 1136 | 1137 | `true` on success, `false` on failure 1138 | 1139 | ___ 1140 | 1141 | #### link 1142 | 1143 | ▸ `Static`**link**(`old_path`: string, `new_path`: string): bool 1144 | 1145 | *Defined in [assembly/as-wasi.ts:602](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L602)* 1146 | 1147 | Create a hard link 1148 | 1149 | **`old_path`** old path 1150 | 1151 | **`new_path`** new path 1152 | 1153 | ##### Parameters: 1154 | 1155 | Name | Type | 1156 | ------ | ------ | 1157 | `old_path` | string | 1158 | `new_path` | string | 1159 | 1160 | **Returns:** bool 1161 | 1162 | `true` on success, `false` on failure 1163 | 1164 | ___ 1165 | 1166 | #### lstat 1167 | 1168 | ▸ `Static`**lstat**(`path`: string): [FileStat](#classesfilestatmd) 1169 | 1170 | *Defined in [assembly/as-wasi.ts:718](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L718)* 1171 | 1172 | Retrieve information about a file or a symbolic link 1173 | 1174 | **`path`** path 1175 | 1176 | ##### Parameters: 1177 | 1178 | Name | Type | 1179 | ------ | ------ | 1180 | `path` | string | 1181 | 1182 | **Returns:** [FileStat](#classesfilestatmd) 1183 | 1184 | a `FileStat` object 1185 | 1186 | ___ 1187 | 1188 | #### mkdir 1189 | 1190 | ▸ `Static`**mkdir**(`path`: string): bool 1191 | 1192 | *Defined in [assembly/as-wasi.ts:562](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L562)* 1193 | 1194 | Create a new directory 1195 | 1196 | **`path`** path 1197 | 1198 | ##### Parameters: 1199 | 1200 | Name | Type | 1201 | ------ | ------ | 1202 | `path` | string | 1203 | 1204 | **Returns:** bool 1205 | 1206 | `true` on success, `false` on failure 1207 | 1208 | ___ 1209 | 1210 | #### open 1211 | 1212 | ▸ `Static`**open**(`path`: string, `flags?`: string): [Descriptor](#classesdescriptormd) \| null 1213 | 1214 | *Defined in [assembly/as-wasi.ts:495](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L495)* 1215 | 1216 | Open a path 1217 | 1218 | **`path`** path 1219 | 1220 | **`flags`** r, r+, w, wx, w+ or xw+ 1221 | 1222 | ##### Parameters: 1223 | 1224 | Name | Type | Default value | 1225 | ------ | ------ | ------ | 1226 | `path` | string | - | 1227 | `flags` | string | "r" | 1228 | 1229 | **Returns:** [Descriptor](#classesdescriptormd) \| null 1230 | 1231 | a descriptor 1232 | 1233 | ___ 1234 | 1235 | #### readdir 1236 | 1237 | ▸ `Static`**readdir**(`path`: string): Array\ \| null 1238 | 1239 | *Defined in [assembly/as-wasi.ts:772](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L772)* 1240 | 1241 | Get the content of a directory 1242 | 1243 | ##### Parameters: 1244 | 1245 | Name | Type | Description | 1246 | ------ | ------ | ------ | 1247 | `path` | string | the directory path | 1248 | 1249 | **Returns:** Array\ \| null 1250 | 1251 | An array of file names 1252 | 1253 | ___ 1254 | 1255 | #### rename 1256 | 1257 | ▸ `Static`**rename**(`old_path`: string, `new_path`: string): bool 1258 | 1259 | *Defined in [assembly/as-wasi.ts:744](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L744)* 1260 | 1261 | Rename a file 1262 | 1263 | **`old_path`** old path 1264 | 1265 | **`new_path`** new path 1266 | 1267 | ##### Parameters: 1268 | 1269 | Name | Type | 1270 | ------ | ------ | 1271 | `old_path` | string | 1272 | `new_path` | string | 1273 | 1274 | **Returns:** bool 1275 | 1276 | `true` on success, `false` on failure 1277 | 1278 | ___ 1279 | 1280 | #### rmdir 1281 | 1282 | ▸ `Static`**rmdir**(`path`: string): bool 1283 | 1284 | *Defined in [assembly/as-wasi.ts:676](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L676)* 1285 | 1286 | Remove a directory 1287 | 1288 | **`path`** path 1289 | 1290 | ##### Parameters: 1291 | 1292 | Name | Type | 1293 | ------ | ------ | 1294 | `path` | string | 1295 | 1296 | **Returns:** bool 1297 | 1298 | `true` on success, `false` on failure 1299 | 1300 | ___ 1301 | 1302 | #### stat 1303 | 1304 | ▸ `Static`**stat**(`path`: string): [FileStat](#classesfilestatmd) 1305 | 1306 | *Defined in [assembly/as-wasi.ts:693](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L693)* 1307 | 1308 | Retrieve information about a file 1309 | 1310 | **`path`** path 1311 | 1312 | ##### Parameters: 1313 | 1314 | Name | Type | 1315 | ------ | ------ | 1316 | `path` | string | 1317 | 1318 | **Returns:** [FileStat](#classesfilestatmd) 1319 | 1320 | a `FileStat` object 1321 | 1322 | ___ 1323 | 1324 | #### symlink 1325 | 1326 | ▸ `Static`**symlink**(`old_path`: string, `new_path`: string): bool 1327 | 1328 | *Defined in [assembly/as-wasi.ts:633](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L633)* 1329 | 1330 | Create a symbolic link 1331 | 1332 | **`old_path`** old path 1333 | 1334 | **`new_path`** new path 1335 | 1336 | ##### Parameters: 1337 | 1338 | Name | Type | 1339 | ------ | ------ | 1340 | `old_path` | string | 1341 | `new_path` | string | 1342 | 1343 | **Returns:** bool 1344 | 1345 | `true` on success, `false` on failure 1346 | 1347 | ___ 1348 | 1349 | #### unlink 1350 | 1351 | ▸ `Static`**unlink**(`path`: string): bool 1352 | 1353 | *Defined in [assembly/as-wasi.ts:659](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L659)* 1354 | 1355 | Unlink a file 1356 | 1357 | **`path`** path 1358 | 1359 | ##### Parameters: 1360 | 1361 | Name | Type | 1362 | ------ | ------ | 1363 | `path` | string | 1364 | 1365 | **Returns:** bool 1366 | 1367 | `true` on success, `false` on failure 1368 | 1369 | 1370 | 1371 | 1372 | **[as-wasi](#readmemd)** 1373 | 1374 | > [Globals](#readmemd) / Performance 1375 | 1376 | ## Class: Performance 1377 | 1378 | ### Hierarchy 1379 | 1380 | * **Performance** 1381 | 1382 | ### Index 1383 | 1384 | #### Methods 1385 | 1386 | * [now](#now) 1387 | 1388 | ### Methods 1389 | 1390 | #### now 1391 | 1392 | ▸ `Static`**now**(): f64 1393 | 1394 | *Defined in [assembly/as-wasi.ts:905](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L905)* 1395 | 1396 | **Returns:** f64 1397 | 1398 | 1399 | 1400 | 1401 | **[as-wasi](#readmemd)** 1402 | 1403 | > [Globals](#readmemd) / Process 1404 | 1405 | ## Class: Process 1406 | 1407 | ### Hierarchy 1408 | 1409 | * **Process** 1410 | 1411 | ### Index 1412 | 1413 | #### Methods 1414 | 1415 | * [exit](#exit) 1416 | 1417 | ### Methods 1418 | 1419 | #### exit 1420 | 1421 | ▸ `Static`**exit**(`status`: u32): void 1422 | 1423 | *Defined in [assembly/as-wasi.ts:920](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L920)* 1424 | 1425 | Cleanly terminate the current process 1426 | 1427 | ##### Parameters: 1428 | 1429 | Name | Type | Description | 1430 | ------ | ------ | ------ | 1431 | `status` | u32 | exit code | 1432 | 1433 | **Returns:** void 1434 | 1435 | 1436 | 1437 | 1438 | **[as-wasi](#readmemd)** 1439 | 1440 | > [Globals](#readmemd) / Random 1441 | 1442 | ## Class: Random 1443 | 1444 | ### Hierarchy 1445 | 1446 | * **Random** 1447 | 1448 | ### Index 1449 | 1450 | #### Methods 1451 | 1452 | * [randomBytes](#randombytes) 1453 | * [randomFill](#randomfill) 1454 | 1455 | ### Methods 1456 | 1457 | #### randomBytes 1458 | 1459 | ▸ `Static`**randomBytes**(`len`: usize): Uint8Array 1460 | 1461 | *Defined in [assembly/as-wasi.ts:884](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L884)* 1462 | 1463 | Return an array of random bytes 1464 | 1465 | ##### Parameters: 1466 | 1467 | Name | Type | Description | 1468 | ------ | ------ | ------ | 1469 | `len` | usize | length | 1470 | 1471 | **Returns:** Uint8Array 1472 | 1473 | ___ 1474 | 1475 | #### randomFill 1476 | 1477 | ▸ `Static`**randomFill**(`buffer`: ArrayBuffer): void 1478 | 1479 | *Defined in [assembly/as-wasi.ts:867](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L867)* 1480 | 1481 | Fill a buffer with random data 1482 | 1483 | ##### Parameters: 1484 | 1485 | Name | Type | Description | 1486 | ------ | ------ | ------ | 1487 | `buffer` | ArrayBuffer | An array buffer | 1488 | 1489 | **Returns:** void 1490 | 1491 | 1492 | 1493 | 1494 | **[as-wasi](#readmemd)** 1495 | 1496 | > [Globals](#readmemd) / StringUtils 1497 | 1498 | ## Class: StringUtils 1499 | 1500 | ### Hierarchy 1501 | 1502 | * **StringUtils** 1503 | 1504 | ### Index 1505 | 1506 | #### Methods 1507 | 1508 | * [fromCString](#fromcstring) 1509 | 1510 | ### Methods 1511 | 1512 | #### fromCString 1513 | 1514 | ▸ `Static`**fromCString**(`cstring`: usize): string 1515 | 1516 | *Defined in [assembly/as-wasi.ts:1091](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1091)* 1517 | 1518 | Returns a native string from a zero-terminated C string 1519 | 1520 | ##### Parameters: 1521 | 1522 | Name | Type | 1523 | ------ | ------ | 1524 | `cstring` | usize | 1525 | 1526 | **Returns:** string 1527 | 1528 | native string 1529 | 1530 | 1531 | 1532 | 1533 | **[as-wasi](#readmemd)** 1534 | 1535 | > [Globals](#readmemd) / Time 1536 | 1537 | ## Class: Time 1538 | 1539 | ### Hierarchy 1540 | 1541 | * **Time** 1542 | 1543 | ### Index 1544 | 1545 | #### Properties 1546 | 1547 | * [MILLISECOND](#millisecond) 1548 | * [NANOSECOND](#nanosecond) 1549 | * [SECOND](#second) 1550 | 1551 | #### Methods 1552 | 1553 | * [sleep](#sleep) 1554 | 1555 | ### Properties 1556 | 1557 | #### MILLISECOND 1558 | 1559 | ▪ `Static` **MILLISECOND**: i32 = Time.NANOSECOND * 1000000 1560 | 1561 | *Defined in [assembly/as-wasi.ts:1046](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1046)* 1562 | 1563 | ___ 1564 | 1565 | #### NANOSECOND 1566 | 1567 | ▪ `Static` **NANOSECOND**: i32 = 1 1568 | 1569 | *Defined in [assembly/as-wasi.ts:1045](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1045)* 1570 | 1571 | ___ 1572 | 1573 | #### SECOND 1574 | 1575 | ▪ `Static` **SECOND**: i32 = Time.MILLISECOND * 1000 1576 | 1577 | *Defined in [assembly/as-wasi.ts:1047](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1047)* 1578 | 1579 | ### Methods 1580 | 1581 | #### sleep 1582 | 1583 | ▸ `Static`**sleep**(`nanoseconds`: i32): void 1584 | 1585 | *Defined in [assembly/as-wasi.ts:1051](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L1051)* 1586 | 1587 | ##### Parameters: 1588 | 1589 | Name | Type | 1590 | ------ | ------ | 1591 | `nanoseconds` | i32 | 1592 | 1593 | **Returns:** void 1594 | 1595 | 1596 | 1597 | 1598 | **[as-wasi](#readmemd)** 1599 | 1600 | > [Globals](#readmemd) / WASIError 1601 | 1602 | ## Class: WASIError 1603 | 1604 | A WASI error 1605 | 1606 | ### Hierarchy 1607 | 1608 | * Error 1609 | 1610 | ↳ **WASIError** 1611 | 1612 | ### Index 1613 | 1614 | #### Constructors 1615 | 1616 | * [constructor](#constructor) 1617 | 1618 | #### Properties 1619 | 1620 | * [message](#message) 1621 | * [name](#name) 1622 | * [stack](#stack) 1623 | 1624 | #### Methods 1625 | 1626 | * [toString](#tostring) 1627 | 1628 | ### Constructors 1629 | 1630 | #### constructor 1631 | 1632 | \+ **new WASIError**(`message?`: string): [WASIError](#classeswasierrormd) 1633 | 1634 | *Overrides void* 1635 | 1636 | *Defined in [assembly/as-wasi.ts:60](https://github.com/jedisct1/as-wasi/blob/e1dfc1b/assembly/as-wasi.ts#L60)* 1637 | 1638 | ##### Parameters: 1639 | 1640 | Name | Type | Default value | 1641 | ------ | ------ | ------ | 1642 | `message` | string | "" | 1643 | 1644 | **Returns:** [WASIError](#classeswasierrormd) 1645 | 1646 | ### Properties 1647 | 1648 | #### message 1649 | 1650 | • **message**: string 1651 | 1652 | *Inherited from [WASIError](#classeswasierrormd).[message](#message)* 1653 | 1654 | *Defined in node_modules/assemblyscript/std/assembly/index.d.ts:1718* 1655 | 1656 | Message provided on construction. 1657 | 1658 | ___ 1659 | 1660 | #### name 1661 | 1662 | • **name**: string 1663 | 1664 | *Inherited from [WASIError](#classeswasierrormd).[name](#name)* 1665 | 1666 | *Defined in node_modules/assemblyscript/std/assembly/index.d.ts:1715* 1667 | 1668 | Error name. 1669 | 1670 | ___ 1671 | 1672 | #### stack 1673 | 1674 | • `Optional` **stack**: undefined \| string 1675 | 1676 | *Inherited from [WASIError](#classeswasierrormd).[stack](#stack)* 1677 | 1678 | *Defined in node_modules/assemblyscript/std/assembly/index.d.ts:1721* 1679 | 1680 | Stack trace. 1681 | 1682 | ### Methods 1683 | 1684 | #### toString 1685 | 1686 | ▸ **toString**(): string 1687 | 1688 | *Inherited from [WASIError](#classeswasierrormd).[toString](#tostring)* 1689 | 1690 | *Defined in node_modules/assemblyscript/std/assembly/index.d.ts:1727* 1691 | 1692 | Method returns a string representing the specified Error class. 1693 | 1694 | **Returns:** string 1695 | --------------------------------------------------------------------------------