UNPKG

cerevox

Version:

TypeScript SDK for browser automation and secure command execution in highly available and scalable micro computer environments

103 lines 3.51 kB
import { BaseClass } from './base'; import { Session } from './session'; /** * FileSystem 类 - 提供沙箱环境中的文件系统操作功能 * * 主要功能: * - 文件和目录的读写操作 * - 安全的文件同步(本地 ↔ 沙箱) * - 递归目录同步 * - 二进制文件检测和处理 * - 路径安全验证 * * @example * ```typescript * const fileSystem = new FileSystem(sandbox); * * // 读取文件 * const content = await fileSystem.read('/path/to/file.txt'); * * // 写入文件 * await fileSystem.write('/path/to/file.txt', 'Hello World'); * * // 同步目录 * const localPath = await fileSystem.syncDownloadsDirectory(); * ``` */ export declare class FileSystem extends BaseClass { private session; /** * 创建 FileSystem 实例 * @param sandbox - E2B 沙箱实例 * @param session - Session 实例(用于获取 API 主机地址) * @param options - 可选配置参数 */ constructor(session: Session); /** * 验证路径是否安全,只允许同步 /home/user 目录下的子目录 * @param path - 要验证的路径 * @returns 是否为安全路径 * @private */ private validateSafePathToDownload; /** * 列出沙箱目录中的文件 * @param path - 沙箱中的目录路径 * @returns 文件名列表的 Promise * @throws {Error} 当沙箱未运行或列表操作失败时抛出错误 */ listFiles(path: string): Promise<string[]>; /** * 检查远程路径是否为目录 * @param remotePath - 远程路径 * @returns 是否为目录 * @private */ isDirectory(remotePath: string): Promise<boolean>; mkdir(path: string): Promise<void>; /** * 递归同步目录 * @param remotePath - 远程目录路径 * @param localPath - 本地目录路径 * @returns 同步的文件数量 * @private */ private syncDirectoryRecursive; /** * 向沙箱中写入文件(通过 API 接口) * @param path - 沙箱中的文件路径 * @param content - 要写入的文本内容(仅支持字符串) */ write(path: string, content: string): Promise<void>; /** * 从沙箱中读取文件(通过 API 接口,仅支持 UTF-8 编码) * @param remotePath - 沙箱中的文件路径 * @returns 文件的文本内容 */ read(remotePath: string): Promise<string>; /** * 上传本地文件到沙箱(通过 API 接口) * @param localPath - 本地文件路径 * @param remotePath - 沙箱中的目标路径 */ upload(localPath: string, remotePath: string): Promise<void>; /** * 从沙箱下载文件到本地(通过 API 接口) * @param remotePath - 沙箱中的文件路径 * @param localPath - 本地目标路径 */ download(remotePath: string, localPath: string): Promise<void>; /** * 同步 sandbox 中的 downloads 目录到本地(递归同步所有子目录) * @param dist - 本地目标目录路径,默认为 '/tmp/cerevox/downloads' * @param src - 远程源目录路径,默认为 '/home/user/downloads' * @returns 本地同步目录路径 * @throws {Error} 当路径不安全时抛出错误 */ syncDownloadsDirectory(dist?: string, src?: string, onProgress?: (metaData: { from: string; to: string; count: number; }) => void): Promise<string>; } //# sourceMappingURL=file-system.d.ts.map