fs
Filesystem module. Cross-platform C++ standard filesystem with per-platform extras for watchers and metadata.
- Kind: module (
.owm) - Version: 0.1.0
- Platforms: Linux, Windows
await ow.invoke('fs', 'readText', '/etc/hostname')
Functions
| Function | Signature |
|---|---|
readText |
(path) → string |
readFile |
(path) → { b64 } | { __ow_shm } |
writeFile |
(path, data, encoding?) → null |
readDir |
(path) → { name, type }[] |
stat |
(path) → { size, isFile, isDir, mtimeMs } | null |
mkdir |
(path, recursive?) → null |
remove |
(path, recursive?) → null |
exists |
(path) → boolean |
copy |
(src, dest, overwrite?) → null |
rename |
(oldPath, newPath) → null |
chmod |
(path, mode) → null |
symlink |
(target, linkPath) → null |
readlink |
(path) → string |
lstat |
(path) → { isSymlink, isFile, isDir, isCharDevice, isFifo, isSocket } | null |
realpath |
(path) → string |
mkdtemp |
(prefix?) → string |
access |
(path, mode?) → boolean |
truncate |
(path, size) → null |
utimes |
(path, atimeMs, mtimeMs) → null |
open |
(path, flags?) → { fd }* |
read |
(fd, offset?, length?) → { b64 | __ow_shm, eof } |
write |
(fd, data, offset?) → number |
size |
(fd) → number |
close |
(fd) → null |
watch |
(path, recursive?) → watcherId |
unwatch |
(watcherId) → null |
* open returns a numeric fd serialized as a JSON number (the SDK type is
{ fd } is illustrative; the raw result is the id). Treat the returned value as
the handle.
Return shapes
// readFile, file >= 256 KB
{ __ow_shm: { id: string, size: number } }
// readFile, file < 256 KB
{ b64: string }
// stat
{ size: number, isFile: boolean, isDir: boolean, mtimeMs: number } | null
// lstat (does NOT follow symlinks)
{ isSymlink, isFile, isDir, isCharDevice, isFifo, isSocket } | null
Details
writeFilecreates missing parent directories.encodingis'utf8'(default) or'base64'.remove(path, true)usesremove_all;remove(path, false)removes an empty directory or a file.copyis always recursive;overwritecontrolsoverwrite_existing.chmodtakes a numeric octal mode (e.g.0o644).mkdtempuses amkdtemp(3)-style template; Windows v1 returns an error.utimesis not implemented on Windows v1 (returns an error).accessdefault mode is read (4); on Windows it falls back toexists.readdefault length is 4 MB; chunks ≥ 256 KB return a__ow_shmhandle.openflags:r,w,a,r+,w+.
Events
watch emits fs.watch with batched changes (~50 ms):
{ watcherId: number, events: [{ type: string, path: string }] }
The watcher is bound to the window that registered it.
Platform notes
- Watchers: inotify (Linux),
ReadDirectoryChangesW(Windows). chmodfollows POSIX semantics; on Windows only the read-only bit matters.- The Windows implementation is present but marked
VERIFY IN CI.