🚧 VeloxKit is pre-release software. APIs may change before v1.0. Get started →
Documentation
APIs & Bindings
fs (File System)

fs Stable WINMACLNX

File system access. All paths support ~ for the home directory and platform-specific separators are normalized automatically.

Requires capability: "fs"

Import

import { fs } from 'veloxkit'

Reading files

// Text
const content = await fs.readText('~/Documents/notes.txt')
 
// Binary
const buffer = await fs.readBytes('~/Downloads/image.png')
 
// JSON (parsed automatically)
const config = await fs.readJSON<Config>('~/config.json')
 
// Stream (for large files)
const stream = fs.createReadStream('~/large-file.csv')

Writing files

await fs.writeText('~/output.txt', 'Hello, world!')
await fs.writeBytes('~/image.png', buffer)
await fs.writeJSON('~/config.json', { theme: 'dark' })
await fs.appendText('~/log.txt', `${new Date().toISOString()} — event\n`)

Directory operations

// List directory
const entries = await fs.readDir('~/Documents')
// → [{ name: 'notes.txt', type: 'file', size: 1024, modified: Date }, ...]
 
// Recursive
const all = await fs.readDir('~/Projects', { recursive: true })
 
// Create directory
await fs.mkdir('~/Documents/my-app', { recursive: true })
 
// Remove
await fs.remove('~/temp/file.txt')
await fs.remove('~/temp', { recursive: true })
 
// Rename / move
await fs.rename('~/old-name.txt', '~/new-name.txt')
await fs.copy('~/source.txt', '~/dest.txt')

Metadata

const stat = await fs.stat('~/file.txt')
stat.size       // bytes
stat.modified   // Date
stat.created    // Date
stat.isFile     // boolean
stat.isDir      // boolean

Watching files

const watcher = fs.watch('~/Documents', (event) => {
  console.log(event.type)  // 'created' | 'modified' | 'deleted' | 'renamed'
  console.log(event.path)
})
 
// Stop watching
watcher.stop()

App data directory

// Resolves to platform-appropriate app data dir
const dataDir = fs.appDataDir()
// macOS:   ~/Library/Application Support/<app-name>
// Windows: %APPDATA%\<app-name>
// Linux:   ~/.local/share/<app-name>
 
const logPath = fs.join(dataDir, 'logs', 'app.log')

Path utilities

fs.join('~/Documents', 'notes', 'file.txt')  // → '/Users/you/Documents/notes/file.txt'
fs.dirname('/path/to/file.txt')               // → '/path/to'
fs.basename('/path/to/file.txt')              // → 'file.txt'
fs.extname('file.txt')                        // → '.txt'
fs.exists('~/file.txt')                       // → Promise<boolean>