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.
example/vfs_example.dart
import 'dart:convert';
import 'dart:typed_data';
import 'package:vfs/vfs.dart';
void main() {
final vfs = MemoryVFS(stdin: utf8.encode('input'));
vfs.mountPreopen(fd: 3, guestPath: '/workspace');
vfs.directory('/workspace').create();
vfs.file('/workspace/hello.txt').write(utf8.encode('hello'));
final fileFd = vfs.pathOpen(3, 'hello.txt', mode: VFSOpenMode.readWrite);
final prefix = Uint8List(5);
vfs.read(fileFd, prefix);
print('read: ${utf8.decode(prefix)}');
vfs.seek(fileFd, 0, whence: VFSWhence.end);
vfs.write(fileFd, utf8.encode(' world'));
vfs.close(fileFd);
print('file: ${utf8.decode(vfs.file('/workspace/hello.txt').read())}');
print('prestat: ${vfs.fdPrestatDirName(3)}');
print('stat type: ${vfs.pathFilestatGet(3, 'hello.txt').type}');
final stdinBuffer = Uint8List(8);
final stdinCount = vfs.read(stdinFileDescriptor, stdinBuffer);
print('stdin: ${utf8.decode(stdinBuffer.sublist(0, stdinCount))}');
vfs.write(stdoutFileDescriptor, utf8.encode('captured stdout'));
print('stdout bytes: ${utf8.decode(vfs.stdoutBytes)}');
}