@lightbery/virtual-file-tree@1.0.5Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
A tool for creating virtual file tree.
This package works with Node.js, BunIt is unknown whether this package works with Cloudflare Workers


JSR Score
100%
Published
a year ago (1.0.5)
Virtual File Tree
A tool for creating virtual file tree.
Example
import VirtualFileTree from './Virtual-File-Tree' const fileTree = new VirtualFileTree() fileTree.createFolder('Test') fileTree.writeFile('Test/A.txt', Buffer.from('hi'))
Installation
You can simply copy Virtual-File-Tree.ts
into your project or use JSR to install.
Contents
VirtualFileTree
import VirtualFileTree from './Virtual-File-Tree' new VirtualFileTree() // Create a virtual file tree
loadFileTree()
.loadFileTree(<data>) // Load the file tree
data <string>
| The source you want to load the file tree (should be the output of.saveFileTree()
).
return <void>
saveFileTree()
.saveFileTree() // Save the file tree
return <void>
(A JSON string)
createFolder()
.createFolder(<virtualPath>, <options>) // Create a folder
virtualPath <string>
| The path of the folder in the virtual file tree.options <undefined | object>
| Options for creating the folder.recursive <boolean>
| If enable, it'll create the missing parent folders.Default: false
return <void>
writeFile()
.writeFile(<virtualPath>, <data>, <options>) // Write a file
virtualPath <string>
| The path of the file in the virtual file tree.data <Buffer>
| The data you want to write.options <undefined | object>
| Options for creating the file.recursive <boolean>
| If enable, it'll create the missing parent folders.Default: false
return <void>
delete()
.delete(<virtualPath>) // Delete a folder or file
virtualPath <string>
| The path of the file in the virtual file tree.
return <undefined>
readFolder()
.readFolder(<virtualPath>, <options>) // Read a folder
virtualPath <string>
| The path of the folder in the virtual file tree.options <undefined | object>
| Options for reading the folder.recursive <boolean>
| Get all the children of the folder.Default: false
fullPath <boolean>
| Get the full path of the files.Default: false
noFolder <boolean>
| Filter out folders.Default: false
return <void>
readFile()
.readFile(<virtualPath>, <options>) // Read a file
virtualPath <string>
| The path of the file in the virtual file tree.options <undefined | object>
| Options for reading the file.encoding <'buffer' | 'utf8' | 'base64' | 'hex'>
| The encoding of the data.Default: 'buffer'
return <void>
exist()
.exist(<virtualPath>) // Check if a path exist
virtualPath <string>
| The path of the file in the virtual file tree.
return <boolean>
getStats()
.getStats(<virtualPath>) // Get the stats of a file
virtualPath <string>
| The path of the file in the virtual file tree.
return <FolderStats | FileStats>
loadFolderFromFS()
.loadFolderFromFS(<realPath>, <virtualPath>, <options>) // Load folder from the real file system
realPath <string>
| The path of the folder you want to load from.virtualPath <string>
| The path of the folder in the virtual file tree.options <undefined | object>
| Options for reading the folder.recursive <boolean>
| If enable, it'll create the missing parent folders.Default: false
return <void>
loadFileFromFS()
.loadFileFromFS(<realPath>, <virtualPath>, <options>) // Load file from the real file system
realPath <string>
| The path of the file you want to load from.virtualPath <string>
| The path of the file in the virtual file tree.options <undefined | object>
| Options for reading the folder.recursive <boolean>
| If enable, it'll create the missing parent folders.Default: false
return <void>
FolderStats
interface FolderStats { type: 'folder', childrens: number }
FileStats
interface FolderStats { type: 'file', size: number }
Built and signed on
GitHub Actions
Add Package
pnpm i jsr:@lightbery/virtual-file-tree
pnpm dlx jsr add @lightbery/virtual-file-tree
Import symbol
import * as virtual_file_tree from "@lightbery/virtual-file-tree";
Add Package
yarn add jsr:@lightbery/virtual-file-tree
yarn dlx jsr add @lightbery/virtual-file-tree
Import symbol
import * as virtual_file_tree from "@lightbery/virtual-file-tree";
Add Package
vlt install jsr:@lightbery/virtual-file-tree
Import symbol
import * as virtual_file_tree from "@lightbery/virtual-file-tree";
Add Package
npx jsr add @lightbery/virtual-file-tree
Import symbol
import * as virtual_file_tree from "@lightbery/virtual-file-tree";
Add Package
bunx jsr add @lightbery/virtual-file-tree
Import symbol
import * as virtual_file_tree from "@lightbery/virtual-file-tree";