vfs 0.0.1-alpha copy "vfs: ^0.0.1-alpha" to clipboard
vfs: ^0.0.1-alpha copied to clipboard

A pure Dart virtual file system with an int file-descriptor boundary.

vfs #

vfs is a pure Dart virtual file system with an int file-descriptor boundary and a Preview1-oriented host API.

This package is designed for code that wants a small, testable VFS with Unix-style descriptor operations such as open, read, write, seek, and close, while also supporting preopened directories and path-based operations such as pathOpen and pathFilestatGet.

Features #

  • fixed stdio descriptors: 0, 1, 2
  • in-memory file and directory storage
  • preopened directories and dirfd-relative path resolution
  • int fd operations for open, read, write, seek, and close
  • descriptor metadata via fdFdstatGet, fdFilestatGet, and fdPrestatGet
  • typed VFSFile and VFSDirectory accessors
  • structured VFSException errors
  • pure Dart with no platform dependencies

Getting started #

Add the package:

dependencies:
  vfs: ^0.0.1-alpha

Usage #

import 'dart:convert';
import 'dart:typed_data';

import 'package:vfs/vfs.dart';

void main() {
  final vfs = MemoryVFS(stdin: utf8.encode('hello'));
  vfs.mountPreopen(fd: 3, guestPath: '/sandbox');

  vfs.file('/sandbox/data.txt').write(utf8.encode('abc'));

  final fd = vfs.pathOpen(3, 'data.txt', mode: VFSOpenMode.readWrite);
  final buffer = Uint8List(3);
  vfs.read(fd, buffer);
  vfs.seek(fd, 0, whence: VFSWhence.end);
  vfs.write(fd, utf8.encode('def'));
  vfs.close(fd);

  print(utf8.decode(vfs.file('/sandbox/data.txt').read())); // abcdef
}

Status #

This is an early prerelease focused on a minimal in-memory backend and a Preview1-oriented descriptor surface. Additional backends and richer semantics may be added later.

0
likes
150
points
6
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A pure Dart virtual file system with an int file-descriptor boundary.

Topics

#filesystem #virtual-filesystem #fd #wasi

License

MIT (license)

More

Packages that depend on vfs