vfs 0.0.1-alpha
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 fdoperations foropen,read,write,seek, andclose- descriptor metadata via
fdFdstatGet,fdFilestatGet, andfdPrestatGet - typed
VFSFileandVFSDirectoryaccessors - structured
VFSExceptionerrors - 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.