@ooneex/fs 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import{watch as F}from"fs";import{cp as S,mkdir as m,readdir as B,rename as g,rm as P}from"fs/promises";import{basename as w,dirname as D,join as _}from"path";import{Exception as k}from"@ooneex/exception";import{HttpStatus as T}from"@ooneex/http-status";class Q extends k{constructor(H,R={}){super(H,{status:T.Code.InternalServerError,data:R});this.name="DirectoryException"}}import{basename as v,dirname as E,extname as j,join as x}from"path";import{Exception as N}from"@ooneex/exception";import{HttpStatus as z}from"@ooneex/http-status";class V extends N{constructor(H,R={}){super(H,{status:z.Code.InternalServerError,data:R});this.name="FileException"}}class U{path;options;constructor(H,R){let J=H instanceof URL?H.pathname:H,q=J.startsWith("/"),K=x(...J.split(/[/\\]/));this.path=q?`/${K}`:K,this.options=R}getBunFile(){return Bun.file(this.path,this.options)}getPath(){return this.path}getName(){return v(this.path)}getExtension(){let H=j(this.path);return H.startsWith(".")?H.slice(1):H}getDirectory(){return new $(E(this.path))}getSize(){return this.getBunFile().size}getType(){return this.getBunFile().type}async exists(){try{return(await this.getBunFile().stat()).isFile()}catch{return!1}}async text(){try{return await this.getBunFile().text()}catch(H){throw new V(`Failed to read file as text: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}async json(){try{return await this.getBunFile().json()}catch(H){throw new V(`Failed to read file as JSON: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}async arrayBuffer(){try{return await this.getBunFile().arrayBuffer()}catch(H){throw new V(`Failed to read file as ArrayBuffer: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}async bytes(){try{return await this.getBunFile().bytes()}catch(H){throw new V(`Failed to read file as Uint8Array: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}stream(){return this.getBunFile().stream()}streamAsText(){let H=this.getBunFile().stream(),R=new TextDecoder;return new ReadableStream({async start(J){let q=H.getReader();try{while(!0){let{done:K,value:Y}=await q.read();if(K)break;J.enqueue(R.decode(Y,{stream:!0}))}J.close()}catch(K){J.error(K)}finally{q.releaseLock()}}})}streamAsJson(){let H=this.getBunFile().stream(),R=new TextDecoder,J="",q=0,K=!1,Y=!1,G=-1,O=!1;return new ReadableStream({async start(I){let C=H.getReader();try{while(!0){let{done:M,value:L}=await C.read();if(M)break;J+=R.decode(L,{stream:!0});let X=0;while(X<J.length){let Z=J[X];if(Y){Y=!1,X++;continue}if(Z==="\\"&&K){Y=!0,X++;continue}if(Z==='"'){K=!K,X++;continue}if(K){X++;continue}if(Z==="["&&!O){O=!0,X++;continue}if(Z==="{"||Z==="["){if(q===0)G=X;q++}else if(Z==="}"||Z==="]"){if(q--,q===0&&G!==-1){let W=J.slice(G,X+1);try{let A=JSON.parse(W);I.enqueue(A)}catch{}J=J.slice(X+1),X=-1,G=-1}}X++}}I.close()}catch(M){I.error(M)}finally{C.releaseLock()}}})}async write(H){try{return await Bun.write(this.path,H)}catch(R){throw new V(`Failed to write to file: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}async append(H){try{let R=this.getBunFile(),q=await R.exists()?await R.bytes():new Uint8Array(0),K=typeof H==="string"?new TextEncoder().encode(H):H,Y=new Uint8Array(q.length+K.length);return Y.set(q),Y.set(K,q.length),await Bun.write(this.path,Y)}catch(R){throw new V(`Failed to append to file: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}async copy(H){try{return await Bun.write(H,this.getBunFile()),new U(H)}catch(R){throw new V(`Failed to copy file: ${this.path}`,{path:this.path,destination:H,error:R instanceof Error?R.message:String(R)})}}async delete(){try{await this.getBunFile().delete()}catch(H){throw new V(`Failed to delete file: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}async download(H){try{let R=await fetch(H);if(!R.ok)throw new V(`HTTP error: ${R.status} ${R.statusText}`);return await Bun.write(this.path,R)}catch(R){throw new V(`Failed to download file from URL: ${H.toString()}`,{path:this.path,url:H.toString(),error:R instanceof Error?R.message:String(R)})}}writer(H){return this.getBunFile().writer(H)}}class ${path;constructor(H){let R=H.startsWith("/"),J=_(...H.split(/[/\\]/));this.path=R?`/${J}`:J}getPath(){return this.path}getName(){return w(this.path)}getParent(){return D(this.path)}async exists(){try{return(await Bun.file(this.path).stat()).isDirectory()}catch{return!1}}async mkdir(H){try{await m(this.path,{recursive:H?.recursive??!0,mode:H?.mode})}catch(R){throw new Q(`Failed to create directory: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}async rm(H){try{await P(this.path,{recursive:H?.recursive??!0,force:H?.force??!1})}catch(R){throw new Q(`Failed to delete directory: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}async ls(H){try{return await B(this.path,{recursive:H?.recursive??!1})}catch(R){throw new Q(`Failed to list directory contents: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}async lsWithTypes(H){try{return await B(this.path,{withFileTypes:!0,recursive:H?.recursive??!1})}catch(R){throw new Q(`Failed to list directory contents with types: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}async cp(H,R){try{await S(this.path,H,{recursive:R?.recursive??!0,force:R?.overwrite??!1})}catch(J){throw new Q(`Failed to copy directory: ${this.path}`,{path:this.path,destination:H,error:J instanceof Error?J.message:String(J)})}}async mv(H){try{await g(this.path,H)}catch(R){throw new Q(`Failed to move directory: ${this.path}`,{path:this.path,destination:H,error:R instanceof Error?R.message:String(R)})}}async stat(){try{return await Bun.file(this.path).stat()}catch(H){throw new Q(`Failed to get directory stats: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}watch(H,R){return F(this.path,{recursive:R?.recursive??!1},H)}async isEmpty(){try{return(await B(this.path)).length===0}catch(H){throw new Q(`Failed to check if directory is empty: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}async getSize(){try{return await this.calculateSize(this.path)}catch(H){throw new Q(`Failed to calculate directory size: ${this.path}`,{path:this.path,error:H instanceof Error?H.message:String(H)})}}async getFiles(H){try{let J=(await B(this.path,{withFileTypes:!0,recursive:H?.recursive??!1})).filter((q)=>q.isFile()).map((q)=>{if(q.parentPath&&q.parentPath!==this.path){let K=q.parentPath.slice(this.path.length+1);return _(K,q.name)}return q.name});if(H?.pattern){let q=H.pattern;J=J.filter((K)=>q.test(K))}return J.map((q)=>new U(_(this.path,q)))}catch(R){throw new Q(`Failed to get files from directory: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}async getDirectories(H){try{let J=(await B(this.path,{withFileTypes:!0,recursive:H?.recursive??!1})).filter((q)=>q.isDirectory()).map((q)=>{if(q.parentPath&&q.parentPath!==this.path){let K=q.parentPath.slice(this.path.length+1);return _(K,q.name)}return q.name});if(H?.pattern){let q=H.pattern;J=J.filter((K)=>q.test(K))}return J.map((q)=>new $(_(this.path,q)))}catch(R){throw new Q(`Failed to get directories from directory: ${this.path}`,{path:this.path,error:R instanceof Error?R.message:String(R)})}}cd(...H){return new $(_(this.path,...H))}async calculateSize(H){let R=0,J=await B(H,{withFileTypes:!0});for(let q of J){let K=_(H,q.name);if(q.isDirectory())R+=await this.calculateSize(K);else if(q.isFile())R+=Bun.file(K).size}return R}}export{V as FileException,U as File,Q as DirectoryException,$ as Directory};
3
+
4
+ //# debugId=329F88F8B0F876C764756E2164756E21
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/Directory.ts", "src/DirectoryException.ts", "src/File.ts", "src/FileException.ts"],
4
+ "sourcesContent": [
5
+ "import type { Dirent, Stats } from \"node:fs\";\nimport { watch } from \"node:fs\";\nimport { cp, mkdir, readdir, rename, rm } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { DirectoryException } from \"./DirectoryException\";\nimport { File } from \"./File\";\nimport type {\n DirectoryCopyOptionsType,\n DirectoryCreateOptionsType,\n DirectoryDeleteOptionsType,\n DirectoryGetDirectoriesOptionsType,\n DirectoryGetFilesOptionsType,\n DirectoryListOptionsType,\n DirectoryWatchCallbackType,\n DirectoryWatcherType,\n DirectoryWatchOptionsType,\n IDirectory,\n IFile,\n} from \"./types\";\n\n/**\n * A class for performing directory operations using Bun's optimized fs APIs.\n *\n * @example\n * ```typescript\n * import { Directory } from \"@ooneex/fs\";\n *\n * const dir = new Directory(\"/path/to/directory\");\n *\n * // Create directory\n * await dir.mkdir();\n *\n * // List contents\n * const files = await dir.ls();\n *\n * // Check if empty\n * if (await dir.isEmpty()) {\n * await dir.rm();\n * }\n * ```\n */\nexport class Directory implements IDirectory {\n private readonly path: string;\n\n /**\n * Creates a new Directory instance.\n *\n * @param path - The directory path as a string\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n * const homeDir = new Directory(\"~/Documents\");\n * const relativeDir = new Directory(\"./src\");\n * ```\n */\n constructor(path: string) {\n const isAbsolute = path.startsWith(\"/\");\n const normalized = join(...path.split(/[/\\\\]/));\n this.path = isAbsolute ? `/${normalized}` : normalized;\n }\n\n /**\n * Returns the directory path.\n *\n * @returns The absolute or relative path of the directory\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/mydir\");\n * console.log(dir.getPath()); // \"/path/to/mydir\"\n * ```\n */\n public getPath(): string {\n return this.path;\n }\n\n /**\n * Returns the directory name.\n *\n * @returns The base name of the directory\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/mydir\");\n * console.log(dir.getName()); // \"mydir\"\n * ```\n */\n public getName(): string {\n return basename(this.path);\n }\n\n /**\n * Returns the parent directory path.\n *\n * @returns The path of the parent directory\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/mydir\");\n * console.log(dir.getParent()); // \"/path/to\"\n * ```\n */\n public getParent(): string {\n return dirname(this.path);\n }\n\n /**\n * Checks if the directory exists.\n *\n * @returns A promise that resolves to true if the directory exists\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n *\n * if (await dir.exists()) {\n * console.log(\"Directory exists!\");\n * } else {\n * await dir.mkdir();\n * }\n * ```\n */\n public async exists(): Promise<boolean> {\n try {\n const stats = await Bun.file(this.path).stat();\n return stats.isDirectory();\n } catch {\n return false;\n }\n }\n\n /**\n * Creates the directory on disk.\n *\n * @param options - Optional configuration for directory creation\n * @param options.recursive - Create parent directories if needed (default: true)\n * @param options.mode - Directory permissions (e.g., 0o755)\n * @throws {DirectoryException} If the directory cannot be created\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/new/nested/directory\");\n *\n * // Create with all parent directories (default behavior)\n * await dir.mkdir();\n *\n * // Create with specific permissions\n * await dir.mkdir({ mode: 0o700 });\n *\n * // Create without recursive (fails if parent doesn't exist)\n * await dir.mkdir({ recursive: false });\n * ```\n */\n public async mkdir(options?: DirectoryCreateOptionsType): Promise<void> {\n try {\n await mkdir(this.path, {\n recursive: options?.recursive ?? true,\n mode: options?.mode,\n });\n } catch (error) {\n throw new DirectoryException(`Failed to create directory: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Deletes the directory from disk.\n *\n * @param options - Optional configuration for directory deletion\n * @param options.recursive - Delete contents recursively (default: true)\n * @param options.force - Ignore errors if directory doesn't exist (default: false)\n * @throws {DirectoryException} If the directory cannot be deleted\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n *\n * // Delete directory and all contents\n * await dir.rm();\n *\n * // Delete only if empty\n * await dir.rm({ recursive: false });\n *\n * // Delete without throwing if doesn't exist\n * await dir.rm({ force: true });\n * ```\n */\n public async rm(options?: DirectoryDeleteOptionsType): Promise<void> {\n try {\n await rm(this.path, {\n recursive: options?.recursive ?? true,\n force: options?.force ?? false,\n });\n } catch (error) {\n throw new DirectoryException(`Failed to delete directory: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Lists the contents of the directory.\n *\n * @param options - Optional configuration for listing\n * @param options.recursive - List contents recursively (default: false)\n * @returns A promise that resolves to an array of file/directory names\n * @throws {DirectoryException} If the directory cannot be listed\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n *\n * // List immediate contents\n * const files = await dir.ls();\n * console.log(files); // [\"file1.txt\", \"file2.txt\", \"subdir\"]\n *\n * // List all contents recursively\n * const allFiles = await dir.ls({ recursive: true });\n * console.log(allFiles); // [\"file1.txt\", \"file2.txt\", \"subdir\", \"subdir/nested.txt\"]\n * ```\n */\n public async ls(options?: DirectoryListOptionsType): Promise<string[]> {\n try {\n const entries = await readdir(this.path, {\n recursive: options?.recursive ?? false,\n });\n return entries as string[];\n } catch (error) {\n throw new DirectoryException(`Failed to list directory contents: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Lists the contents of the directory with type information.\n *\n * @param options - Optional configuration for listing\n * @param options.recursive - List contents recursively (default: false)\n * @returns A promise that resolves to an array of Dirent objects\n * @throws {DirectoryException} If the directory cannot be listed\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n * const entries = await dir.lsWithTypes();\n *\n * for (const entry of entries) {\n * if (entry.isFile()) {\n * console.log(`File: ${entry.name}`);\n * } else if (entry.isDirectory()) {\n * console.log(`Directory: ${entry.name}`);\n * } else if (entry.isSymbolicLink()) {\n * console.log(`Symlink: ${entry.name}`);\n * }\n * }\n * ```\n */\n public async lsWithTypes(options?: DirectoryListOptionsType): Promise<Dirent[]> {\n try {\n return await readdir(this.path, {\n withFileTypes: true,\n recursive: options?.recursive ?? false,\n });\n } catch (error) {\n throw new DirectoryException(`Failed to list directory contents with types: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Copies the directory to a destination path.\n *\n * @param destination - The destination directory path\n * @param options - Optional configuration for copying\n * @param options.recursive - Copy contents recursively (default: true)\n * @param options.overwrite - Overwrite existing files (default: false)\n * @throws {DirectoryException} If the directory cannot be copied\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/source\");\n *\n * // Copy directory and all contents\n * await dir.cp(\"/path/to/destination\");\n *\n * // Copy with overwrite\n * await dir.cp(\"/path/to/destination\", { overwrite: true });\n *\n * // Copy only the directory structure (no files)\n * await dir.cp(\"/path/to/destination\", { recursive: false });\n * ```\n */\n public async cp(destination: string, options?: DirectoryCopyOptionsType): Promise<void> {\n try {\n await cp(this.path, destination, {\n recursive: options?.recursive ?? true,\n force: options?.overwrite ?? false,\n });\n } catch (error) {\n throw new DirectoryException(`Failed to copy directory: ${this.path}`, {\n path: this.path,\n destination,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Moves (renames) the directory to a new location.\n *\n * @param destination - The new directory path\n * @throws {DirectoryException} If the directory cannot be moved\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/oldname\");\n *\n * // Rename directory\n * await dir.mv(\"/path/to/newname\");\n *\n * // Move to different location\n * await dir.mv(\"/different/path/dirname\");\n * ```\n */\n public async mv(destination: string): Promise<void> {\n try {\n await rename(this.path, destination);\n } catch (error) {\n throw new DirectoryException(`Failed to move directory: ${this.path}`, {\n path: this.path,\n destination,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Returns the directory statistics.\n *\n * @returns A promise that resolves to a Stats object\n * @throws {DirectoryException} If stats cannot be retrieved\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n * const stats = await dir.stat();\n *\n * console.log(stats.isDirectory()); // true\n * console.log(stats.mode); // 16877 (permissions)\n * console.log(stats.mtime); // Date object (modification time)\n * console.log(stats.birthtime); // Date object (creation time)\n * ```\n */\n public async stat(): Promise<Stats> {\n try {\n return await Bun.file(this.path).stat();\n } catch (error) {\n throw new DirectoryException(`Failed to get directory stats: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Watches the directory for changes.\n *\n * @param callback - Function called when changes are detected\n * @param options - Optional configuration for watching\n * @param options.recursive - Watch subdirectories recursively (default: false)\n * @returns A FSWatcher that can be closed to stop watching\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n *\n * // Watch for changes\n * const watcher = dir.watch((event, filename) => {\n * console.log(`${event}: ${filename}`);\n * });\n *\n * // Watch recursively\n * const recursiveWatcher = dir.watch(\n * (event, filename) => console.log(event, filename),\n * { recursive: true }\n * );\n *\n * // Stop watching\n * watcher.close();\n *\n * // Handle close with SIGINT\n * process.on(\"SIGINT\", () => {\n * watcher.close();\n * process.exit(0);\n * });\n * ```\n */\n public watch(callback: DirectoryWatchCallbackType, options?: DirectoryWatchOptionsType): DirectoryWatcherType {\n return watch(this.path, { recursive: options?.recursive ?? false }, callback);\n }\n\n /**\n * Checks if the directory is empty.\n *\n * @returns A promise that resolves to true if the directory has no contents\n * @throws {DirectoryException} If the directory cannot be checked\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n *\n * if (await dir.isEmpty()) {\n * console.log(\"Directory is empty\");\n * await dir.rm();\n * } else {\n * console.log(\"Directory has contents\");\n * }\n * ```\n */\n public async isEmpty(): Promise<boolean> {\n try {\n const entries = await readdir(this.path);\n return entries.length === 0;\n } catch (error) {\n throw new DirectoryException(`Failed to check if directory is empty: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Calculates the total size of all contents in the directory.\n *\n * @returns A promise that resolves to the total size in bytes\n * @throws {DirectoryException} If the size cannot be calculated\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n * const sizeBytes = await dir.getSize();\n *\n * // Format as human-readable\n * const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(2);\n * console.log(`Directory size: ${sizeMB} MB`);\n * ```\n */\n public async getSize(): Promise<number> {\n try {\n return await this.calculateSize(this.path);\n } catch (error) {\n throw new DirectoryException(`Failed to calculate directory size: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Gets a list of files (not directories) in the directory.\n *\n * @param options - Optional configuration for getting files\n * @param options.recursive - Get files recursively from subdirectories (default: false)\n * @param options.pattern - Regular expression to filter files by name\n * @returns A promise that resolves to an array of File instances\n * @throws {DirectoryException} If the files cannot be listed\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n *\n * // Get immediate files only\n * const files = await dir.getFiles();\n * for (const file of files) {\n * console.log(file.getName());\n * }\n *\n * // Get all files recursively\n * const allFiles = await dir.getFiles({ recursive: true });\n *\n * // Get only TypeScript files\n * const tsFiles = await dir.getFiles({ pattern: /\\.ts$/ });\n *\n * // Get TypeScript files recursively\n * const allTsFiles = await dir.getFiles({ recursive: true, pattern: /\\.tsx?$/ });\n * ```\n */\n public async getFiles(options?: DirectoryGetFilesOptionsType): Promise<IFile[]> {\n try {\n const entries = await readdir(this.path, {\n withFileTypes: true,\n recursive: options?.recursive ?? false,\n });\n\n let filePaths = entries\n .filter((entry) => entry.isFile())\n .map((entry) => {\n if (entry.parentPath && entry.parentPath !== this.path) {\n const relativePath = entry.parentPath.slice(this.path.length + 1);\n return join(relativePath, entry.name);\n }\n return entry.name;\n });\n\n if (options?.pattern) {\n const pattern = options.pattern;\n filePaths = filePaths.filter((filePath) => pattern.test(filePath));\n }\n\n return filePaths.map((filePath) => new File(join(this.path, filePath)));\n } catch (error) {\n throw new DirectoryException(`Failed to get files from directory: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Gets a list of subdirectories (not files) in the directory.\n *\n * @param options - Optional configuration for getting directories\n * @param options.recursive - Get directories recursively from subdirectories (default: false)\n * @param options.pattern - Regular expression to filter directories by name\n * @returns A promise that resolves to an array of Directory instances\n * @throws {DirectoryException} If the directories cannot be listed\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/directory\");\n *\n * // Get immediate subdirectories only\n * const dirs = await dir.getDirectories();\n * for (const subdir of dirs) {\n * console.log(subdir.getName());\n * }\n *\n * // Get all subdirectories recursively\n * const allDirs = await dir.getDirectories({ recursive: true });\n *\n * // Get only directories starting with \"test\"\n * const testDirs = await dir.getDirectories({ pattern: /^test/ });\n *\n * // Get directories recursively matching pattern\n * const srcDirs = await dir.getDirectories({ recursive: true, pattern: /^src/ });\n * ```\n */\n public async getDirectories(options?: DirectoryGetDirectoriesOptionsType): Promise<IDirectory[]> {\n try {\n const entries = await readdir(this.path, {\n withFileTypes: true,\n recursive: options?.recursive ?? false,\n });\n\n let dirPaths = entries\n .filter((entry) => entry.isDirectory())\n .map((entry) => {\n if (entry.parentPath && entry.parentPath !== this.path) {\n const relativePath = entry.parentPath.slice(this.path.length + 1);\n return join(relativePath, entry.name);\n }\n return entry.name;\n });\n\n if (options?.pattern) {\n const pattern = options.pattern;\n dirPaths = dirPaths.filter((dirPath) => pattern.test(dirPath));\n }\n\n return dirPaths.map((dirPath) => new Directory(join(this.path, dirPath)));\n } catch (error) {\n throw new DirectoryException(`Failed to get directories from directory: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Changes to a subdirectory and returns a new Directory instance.\n *\n * @param paths - The relative path segments to the subdirectory\n * @returns A new Directory instance pointing to the subdirectory\n *\n * @example\n * ```typescript\n * const dir = new Directory(\"/path/to/project\");\n *\n * // Navigate to subdirectory\n * const srcDir = dir.cd(\"src\");\n * console.log(srcDir.getPath()); // \"/path/to/project/src\"\n *\n * // Navigate multiple levels with multiple args\n * const componentsDir = dir.cd(\"src\", \"components\", \"ui\");\n * console.log(componentsDir.getPath()); // \"/path/to/project/src/components/ui\"\n *\n * // Navigate to parent\n * const parentDir = dir.cd(\"..\");\n * console.log(parentDir.getPath()); // \"/path/to\"\n *\n * // Chain navigation\n * const deepDir = dir.cd(\"src\").cd(\"components\").cd(\"ui\");\n * ```\n */\n public cd(...paths: string[]): IDirectory {\n return new Directory(join(this.path, ...paths));\n }\n\n private async calculateSize(dirPath: string): Promise<number> {\n let totalSize = 0;\n const entries = await readdir(dirPath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(dirPath, entry.name);\n if (entry.isDirectory()) {\n totalSize += await this.calculateSize(fullPath);\n } else if (entry.isFile()) {\n totalSize += Bun.file(fullPath).size;\n }\n }\n\n return totalSize;\n }\n}\n",
6
+ "import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class DirectoryException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n this.name = \"DirectoryException\";\n }\n}\n",
7
+ "import { basename, dirname, extname, join } from \"node:path\";\nimport type { BunFile } from \"bun\";\nimport { Directory } from \"./Directory\";\nimport { FileException } from \"./FileException\";\nimport type {\n BunFileSinkType,\n FileOptionsType,\n FileWriteDataType,\n FileWriterOptionsType,\n IDirectory,\n IFile,\n} from \"./types\";\n\n/**\n * A class for performing file operations using Bun's optimized file I/O APIs.\n *\n * @example\n * ```typescript\n * import { File } from \"@ooneex/fs\";\n *\n * const file = new File(\"/path/to/file.txt\");\n *\n * // Read file content\n * const content = await file.text();\n *\n * // Write to file\n * await file.write(\"Hello, World!\");\n *\n * // Check if file exists\n * if (await file.exists()) {\n * console.log(\"File exists!\");\n * }\n * ```\n */\nexport class File implements IFile {\n private readonly path: string;\n private readonly options: FileOptionsType | undefined;\n\n /**\n * Creates a new File instance.\n *\n * @param path - The file path as a string or URL\n * @param options - Optional configuration options\n *\n * @example\n * ```typescript\n * // Using string path\n * const file = new File(\"/path/to/file.txt\");\n *\n * // Using URL\n * const file = new File(new URL(\"file:///path/to/file.txt\"));\n *\n * // With custom MIME type\n * const file = new File(\"/path/to/file\", { type: \"application/json\" });\n * ```\n */\n constructor(path: string | URL, options?: FileOptionsType) {\n const pathStr = path instanceof URL ? path.pathname : path;\n const isAbsolute = pathStr.startsWith(\"/\");\n const normalized = join(...pathStr.split(/[/\\\\]/));\n this.path = isAbsolute ? `/${normalized}` : normalized;\n this.options = options;\n }\n\n private getBunFile(): BunFile {\n return Bun.file(this.path, this.options);\n }\n\n /**\n * Returns the file path.\n *\n * @returns The absolute or relative path of the file\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/document.pdf\");\n * console.log(file.getPath()); // \"/path/to/document.pdf\"\n * ```\n */\n public getPath(): string {\n return this.path;\n }\n\n /**\n * Returns the file name including extension.\n *\n * @returns The base name of the file\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/document.pdf\");\n * console.log(file.getName()); // \"document.pdf\"\n * ```\n */\n public getName(): string {\n return basename(this.path);\n }\n\n /**\n * Returns the file extension without the leading dot.\n *\n * @returns The file extension or empty string if none\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/document.pdf\");\n * console.log(file.getExtension()); // \"pdf\"\n *\n * const noExt = new File(\"/path/to/README\");\n * console.log(noExt.getExtension()); // \"\"\n * ```\n */\n public getExtension(): string {\n const ext = extname(this.path);\n return ext.startsWith(\".\") ? ext.slice(1) : ext;\n }\n\n /**\n * Returns the directory containing the file.\n *\n * @returns The parent directory as an IDirectory instance\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/document.pdf\");\n * const dir = file.getDirectory();\n * console.log(dir.getPath()); // \"/path/to\"\n * ```\n */\n public getDirectory(): IDirectory {\n return new Directory(dirname(this.path));\n }\n\n /**\n * Returns the file size in bytes.\n *\n * @returns The size of the file in bytes, or 0 if file doesn't exist\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/document.pdf\");\n * console.log(file.getSize()); // 1024\n * ```\n */\n public getSize(): number {\n return this.getBunFile().size;\n }\n\n /**\n * Returns the MIME type of the file.\n *\n * @returns The MIME type string (e.g., \"text/plain\", \"application/json\")\n *\n * @example\n * ```typescript\n * const txtFile = new File(\"/path/to/file.txt\");\n * console.log(txtFile.getType()); // \"text/plain;charset=utf-8\"\n *\n * const jsonFile = new File(\"/path/to/data.json\");\n * console.log(jsonFile.getType()); // \"application/json;charset=utf-8\"\n * ```\n */\n public getType(): string {\n return this.getBunFile().type;\n }\n\n /**\n * Checks if the file exists on disk.\n *\n * @returns A promise that resolves to true if the file exists\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/file.txt\");\n *\n * if (await file.exists()) {\n * console.log(\"File exists!\");\n * } else {\n * console.log(\"File not found\");\n * }\n * ```\n */\n public async exists(): Promise<boolean> {\n try {\n const stats = await this.getBunFile().stat();\n return stats.isFile();\n } catch {\n return false;\n }\n }\n\n /**\n * Reads the file content as a string.\n *\n * @returns A promise that resolves to the file content as a string\n * @throws {FileException} If the file cannot be read\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/file.txt\");\n * const content = await file.text();\n * console.log(content); // \"Hello, World!\"\n * ```\n */\n public async text(): Promise<string> {\n try {\n return await this.getBunFile().text();\n } catch (error) {\n throw new FileException(`Failed to read file as text: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Reads and parses the file content as JSON.\n *\n * @typeParam T - The expected type of the parsed JSON\n * @returns A promise that resolves to the parsed JSON object\n * @throws {FileException} If the file cannot be read or parsed\n *\n * @example\n * ```typescript\n * interface Config {\n * name: string;\n * version: number;\n * }\n *\n * const file = new File(\"/path/to/config.json\");\n * const config = await file.json<Config>();\n * console.log(config.name); // \"my-app\"\n * ```\n */\n public async json<T = unknown>(): Promise<T> {\n try {\n return (await this.getBunFile().json()) as T;\n } catch (error) {\n throw new FileException(`Failed to read file as JSON: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Reads the file content as an ArrayBuffer.\n *\n * @returns A promise that resolves to the file content as an ArrayBuffer\n * @throws {FileException} If the file cannot be read\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/binary.bin\");\n * const buffer = await file.arrayBuffer();\n * const view = new DataView(buffer);\n * console.log(view.getInt32(0)); // First 4 bytes as int32\n * ```\n */\n public async arrayBuffer(): Promise<ArrayBuffer> {\n try {\n return await this.getBunFile().arrayBuffer();\n } catch (error) {\n throw new FileException(`Failed to read file as ArrayBuffer: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Reads the file content as a Uint8Array.\n *\n * @returns A promise that resolves to the file content as a Uint8Array\n * @throws {FileException} If the file cannot be read\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/binary.bin\");\n * const bytes = await file.bytes();\n * console.log(bytes[0]); // First byte\n * console.log(bytes.length); // Total bytes\n * ```\n */\n public async bytes(): Promise<Uint8Array> {\n try {\n return await this.getBunFile().bytes();\n } catch (error) {\n throw new FileException(`Failed to read file as Uint8Array: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Returns a ReadableStream for incremental file reading.\n *\n * @returns A ReadableStream of Uint8Array chunks\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/large-file.txt\");\n * const stream = file.stream();\n *\n * for await (const chunk of stream) {\n * console.log(`Received ${chunk.length} bytes`);\n * }\n * ```\n */\n public stream(): ReadableStream<Uint8Array> {\n return this.getBunFile().stream();\n }\n\n /**\n * Returns a ReadableStream for incremental file reading as text.\n *\n * @returns A ReadableStream of string chunks\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/large-file.txt\");\n * const stream = file.streamAsText();\n *\n * for await (const chunk of stream) {\n * console.log(`Received text: ${chunk}`);\n * }\n * ```\n */\n public streamAsText(): ReadableStream<string> {\n const byteStream = this.getBunFile().stream();\n const decoder = new TextDecoder();\n\n return new ReadableStream<string>({\n async start(controller) {\n const reader = byteStream.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n controller.enqueue(decoder.decode(value, { stream: true }));\n }\n controller.close();\n } catch (error) {\n controller.error(error);\n } finally {\n reader.releaseLock();\n }\n },\n });\n }\n\n /**\n * Returns a ReadableStream for incremental JSON parsing from a JSON array file.\n *\n * Reads a file containing a JSON array and streams each parsed element individually.\n * This is useful for processing large JSON array files without loading everything into memory.\n *\n * @typeParam T - The expected type of each JSON element\n * @returns A ReadableStream of parsed JSON elements\n *\n * @example\n * ```typescript\n * // For a file containing: [{\"id\": 1}, {\"id\": 2}, {\"id\": 3}]\n * const file = new File(\"/path/to/data.json\");\n * const stream = file.streamAsJson<{ id: number }>();\n *\n * for await (const item of stream) {\n * console.log(item.id); // 1, 2, 3\n * }\n * ```\n */\n public streamAsJson<T = unknown>(): ReadableStream<T> {\n const byteStream = this.getBunFile().stream();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let depth = 0;\n let inString = false;\n let isEscape = false;\n let objectStart = -1;\n let arrayStarted = false;\n\n return new ReadableStream<T>({\n async start(controller) {\n const reader = byteStream.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n let i = 0;\n while (i < buffer.length) {\n const char = buffer[i];\n\n if (isEscape) {\n isEscape = false;\n i++;\n continue;\n }\n\n if (char === \"\\\\\" && inString) {\n isEscape = true;\n i++;\n continue;\n }\n\n if (char === '\"') {\n inString = !inString;\n i++;\n continue;\n }\n\n if (inString) {\n i++;\n continue;\n }\n\n if (char === \"[\" && !arrayStarted) {\n arrayStarted = true;\n i++;\n continue;\n }\n\n if (char === \"{\" || char === \"[\") {\n if (depth === 0) {\n objectStart = i;\n }\n depth++;\n } else if (char === \"}\" || char === \"]\") {\n depth--;\n if (depth === 0 && objectStart !== -1) {\n const jsonStr = buffer.slice(objectStart, i + 1);\n try {\n const parsed = JSON.parse(jsonStr) as T;\n controller.enqueue(parsed);\n } catch {\n // Skip invalid JSON\n }\n buffer = buffer.slice(i + 1);\n i = -1;\n objectStart = -1;\n }\n }\n\n i++;\n }\n }\n controller.close();\n } catch (error) {\n controller.error(error);\n } finally {\n reader.releaseLock();\n }\n },\n });\n }\n\n /**\n * Writes data to the file, overwriting existing content.\n *\n * @param data - The data to write (string, Blob, ArrayBuffer, TypedArray, or Response)\n * @returns A promise that resolves to the number of bytes written\n * @throws {FileException} If the file cannot be written\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/file.txt\");\n *\n * // Write string\n * await file.write(\"Hello, World!\");\n *\n * // Write Uint8Array\n * await file.write(new Uint8Array([72, 101, 108, 108, 111]));\n *\n * // Write from Response\n * const response = await fetch(\"https://example.com/data\");\n * await file.write(response);\n * ```\n */\n public async write(data: FileWriteDataType): Promise<number> {\n try {\n return await Bun.write(this.path, data as Parameters<typeof Bun.write>[1]);\n } catch (error) {\n throw new FileException(`Failed to write to file: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Appends data to the end of the file.\n *\n * @param data - The data to append (string or Uint8Array)\n * @returns A promise that resolves to the total number of bytes in the file\n * @throws {FileException} If the file cannot be appended to\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/log.txt\");\n *\n * // Append string\n * await file.append(\"New log entry\\n\");\n *\n * // Append binary data\n * await file.append(new Uint8Array([10, 20, 30]));\n * ```\n */\n public async append(data: string | Uint8Array): Promise<number> {\n try {\n const bunFile = this.getBunFile();\n const fileExists = await bunFile.exists();\n const existingContent = fileExists ? await bunFile.bytes() : new Uint8Array(0);\n\n const newData = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n\n const combined = new Uint8Array(existingContent.length + newData.length);\n combined.set(existingContent);\n combined.set(newData, existingContent.length);\n\n return await Bun.write(this.path, combined);\n } catch (error) {\n throw new FileException(`Failed to append to file: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Copies the file to a destination path.\n *\n * @param destination - The destination file path\n * @returns A promise that resolves to a new File instance for the copied file\n * @throws {FileException} If the file cannot be copied\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/original.txt\");\n * const copiedFile = await file.copy(\"/path/to/backup.txt\");\n *\n * // The original file is preserved\n * console.log(await file.exists()); // true\n * // Access the copied file\n * console.log(await copiedFile.text()); // same content as original\n * ```\n */\n public async copy(destination: string): Promise<IFile> {\n try {\n await Bun.write(destination, this.getBunFile());\n return new File(destination);\n } catch (error) {\n throw new FileException(`Failed to copy file: ${this.path}`, {\n path: this.path,\n destination,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Deletes the file from disk.\n *\n * @throws {FileException} If the file cannot be deleted\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/temp.txt\");\n *\n * if (await file.exists()) {\n * await file.delete();\n * console.log(\"File deleted\");\n * }\n * ```\n */\n public async delete(): Promise<void> {\n try {\n await this.getBunFile().delete();\n } catch (error) {\n throw new FileException(`Failed to delete file: ${this.path}`, {\n path: this.path,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Downloads a file from a URL and saves it to this file's path.\n *\n * @param url - The URL to download the file from\n * @returns A promise that resolves to the number of bytes written\n * @throws {FileException} If the download or write operation fails\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/image.png\");\n *\n * // Download from URL\n * const bytes = await file.download(\"https://example.com/image.png\");\n * console.log(`Downloaded ${bytes} bytes`);\n *\n * // Download with URL object\n * await file.download(new URL(\"https://example.com/data.json\"));\n * ```\n */\n public async download(url: string | URL): Promise<number> {\n try {\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new FileException(`HTTP error: ${response.status} ${response.statusText}`);\n }\n\n return await Bun.write(this.path, response);\n } catch (error) {\n throw new FileException(`Failed to download file from URL: ${url.toString()}`, {\n path: this.path,\n url: url.toString(),\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n /**\n * Returns a FileSink for incremental writing.\n *\n * @param options - Optional configuration for the writer\n * @returns A FileSink instance for buffered writing\n *\n * @example\n * ```typescript\n * const file = new File(\"/path/to/output.txt\");\n * const writer = file.writer({ highWaterMark: 1024 * 1024 }); // 1MB buffer\n *\n * writer.write(\"Line 1\\n\");\n * writer.write(\"Line 2\\n\");\n * writer.flush(); // Flush buffer to disk\n *\n * writer.write(\"Line 3\\n\");\n * writer.end(); // Flush and close\n * ```\n */\n public writer(options?: FileWriterOptionsType): BunFileSinkType {\n return this.getBunFile().writer(options);\n }\n}\n",
8
+ "import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class FileException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n this.name = \"FileException\";\n }\n}\n"
9
+ ],
10
+ "mappings": ";AACA,gBAAS,WACT,aAAS,WAAI,aAAO,YAAS,QAAQ,oBACrC,mBAAS,aAAU,UAAS,aCH5B,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAA2B,CAAU,CAChD,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,oBACxB,MACF,CAAC,EACD,KAAK,KAAO,qBAEhB,CCXA,mBAAS,aAAU,aAAS,UAAS,aCArC,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAAsB,CAAU,CAC3C,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,oBACxB,MACF,CAAC,EACD,KAAK,KAAO,gBAEhB,CDuBO,MAAM,CAAsB,CAChB,KACA,QAoBjB,WAAW,CAAC,EAAoB,EAA2B,CACzD,IAAM,EAAU,aAAgB,IAAM,EAAK,SAAW,EAChD,EAAa,EAAQ,WAAW,GAAG,EACnC,EAAa,EAAK,GAAG,EAAQ,MAAM,OAAO,CAAC,EACjD,KAAK,KAAO,EAAa,IAAI,IAAe,EAC5C,KAAK,QAAU,EAGT,UAAU,EAAY,CAC5B,OAAO,IAAI,KAAK,KAAK,KAAM,KAAK,OAAO,EAclC,OAAO,EAAW,CACvB,OAAO,KAAK,KAcP,OAAO,EAAW,CACvB,OAAO,EA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AAK,KAAK,KAAM,CAAO,CAAC,CAAC,EACxE,MAAO,EAAO,CACd,MAAM,IAAI,EAAmB,6CAA6C,KAAK,OAAQ,CACrF,KAAM,KAAK,KACX,MAAO,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,CAC9D,CAAC,GA8BE,EAAE,IAAI,EAA6B,CACxC,OAAO,IAAI,EAAU,EAAK,KAAK,KAAM,GAAG,CAAK,CAAC,OAGlC,cAAa,CAAC,EAAkC,CAC5D,IAAI,EAAY,EACV,EAAU,MAAM,EAAQ,EAAS,CAAE,cAAe,EAAK,CAAC,EAE9D,QAAW,KAAS,EAAS,CAC3B,IAAM,EAAW,EAAK,EAAS,EAAM,IAAI,EACzC,GAAI,EAAM,YAAY,EACpB,GAAa,MAAM,KAAK,cAAc,CAAQ,EACzC,QAAI,EAAM,OAAO,EACtB,GAAa,IAAI,KAAK,CAAQ,EAAE,KAIpC,OAAO,EAEX",
11
+ "debugId": "329F88F8B0F876C764756E2164756E21",
12
+ "names": []
13
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@ooneex/fs",
3
+ "description": "File system utilities for reading, writing, and manipulating files and directories with async support and error handling",
4
+ "version": "0.0.4",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "LICENSE",
9
+ "README.md",
10
+ "package.json"
11
+ ],
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "license": "MIT",
24
+ "scripts": {
25
+ "build": "bunup",
26
+ "lint": "tsgo --noEmit && bunx biome lint",
27
+ "publish": "bun publish --access public || true",
28
+ "test": "bun test tests"
29
+ },
30
+ "dependencies": {
31
+ "@ooneex/exception": "0.0.1",
32
+ "@ooneex/http-status": "0.0.1"
33
+ },
34
+ "keywords": [
35
+ "bun",
36
+ "file",
37
+ "filesystem",
38
+ "fs",
39
+ "io",
40
+ "ooneex",
41
+ "typescript"
42
+ ]
43
+ }