extractFile
Category: File Operations
Namespace: web.files.extractFile
Description
Extracts a file from the application's Virtual File System (VFS) to the local file system. The VFS contains files embedded in the application during build.
Syntax
const result = await web.files.extractFile({
sourceFile: 'assets/template.html',
targetFile: 'output/template.html'
});
Parameters
- sourceFile (required) - Path to the file in the VFS (relative path within VFS)
- targetFile (required) - Destination path on the local file system (relative or absolute)
Returns
Promise<Object> - Result object:
{
success: boolean,
error?: string
}
Examples
Simple example
const result = await web.files.extractFile({
sourceFile: 'assets/logo.png',
targetFile: 'temp/logo.png'
});
if (result.success) {
console.log('File extracted successfully');
} else {
console.error('Extraction failed:', result.error);
}
Extract template files
// Extract HTML template from VFS
const result = await web.files.extractFile({
sourceFile: 'templates/report.html',
targetFile: 'C:\\Output\\report.html'
});
if (result.success) {
// Now modify the extracted file
const content = await web.files.readTextFile({
filePath: 'C:\\Output\\report.html'
});
// Process content...
}
Extract multiple files
const files = [
{ source: 'assets/style.css', target: 'output/style.css' },
{ source: 'assets/script.js', target: 'output/script.js' },
{ source: 'assets/logo.png', target: 'output/logo.png' }
];
for (const file of files) {
const result = await web.files.extractFile({
sourceFile: file.source,
targetFile: file.target
});
console.log(`${file.source}: ${result.success ? '✓' : '✗'}`);
}
Use Cases
- Extract embedded template files for customization
- Deploy bundled assets to the file system
- Extract default configuration files
- Copy embedded resources to user directories
- Initialize application with default files
Notes
- Files must be embedded in the VFS during application build
- Automatically creates destination directories if needed
- Relative target paths are resolved from the application executable directory
- Use forward slashes (
/) or backslashes (\\) in source paths - Returns
{success: false}if the source file is not found in VFS