Files

为脚本环境提供文件系统操作的核心接口.

继承自 Variable, 表示它在脚本中通常以一个预定义变量的形式存在 (例如 files). 通过此接口, 脚本可以访问应用专属目录、构建文件对象、执行压缩/解压以及进行高效的异步 I/O 操作.

Author

M8Test, [email protected], https://m8test.com

Functions

Link copied to clipboard
abstract fun buildFile(fileBuilder: FileBuilder.() -> Unit): ScriptFile

通过 DSL (领域特定语言) 方式构建一个 ScriptFile 对象.

Link copied to clipboard
abstract override fun close()

关闭当前对象, 如果没有调用本方法则会报错, 当然本方法由系统调用, 不需要手动调用.

Link copied to clipboard
abstract fun getContext(): ScriptContext

获取脚本上下文对象 ScriptContext.

Link copied to clipboard
abstract fun getExternalFilesDir(type: String?): String?

返回所有共享/外部存储设备上特定于应用程序的目录的绝对路径, 应用程序可以在其中放置其拥有的持久文件.

Link copied to clipboard
abstract fun getFilesDir(): String

返回内部存储中该应用专属文件目录的绝对路径.

Link copied to clipboard
abstract fun getGlobalName(): String

获取作为全局变量时的名称.

Link copied to clipboard
abstract fun getPublicType(): Type

获取 Variable 注入到脚本时需要显示的类型.

Link copied to clipboard
abstract fun isClosed(): Boolean

判断当前对象是否已经调用了 close 方法.

Link copied to clipboard
abstract fun isPrefixRequired(): Boolean

是否需要添加前缀, 每种编程语言添加的前缀不一样, 前缀可以通过 Language.getVariablePrefix 获取.

Link copied to clipboard
abstract fun isSuffixRequired(): Boolean

是否需要添加后缀, 每种编程语言添加的后缀不一样, 后缀可以通过 Language.getVariableSuffix 获取.

Link copied to clipboard
abstract fun toReadChannel(scriptFile: ScriptFile, start: Long, endInclusive: Long, coroutineContext: CoroutineContext.() -> Unit?): ByteReadChannel

将一个 ScriptFile 转换为可供异步读取的 ByteReadChannel.

Link copied to clipboard
abstract fun toWriteChannel(scriptFile: ScriptFile, coroutineContext: CoroutineContext.() -> Unit?): ByteWriteChannel

将一个 ScriptFile 转换为可供异步写入的 ByteWriteChannel.

Link copied to clipboard
abstract fun unzipFile(src: ScriptFile, dest: ScriptFile, password: String?): List<ScriptFile>

解压一个 ZIP 文件到指定的目标目录.

Link copied to clipboard
abstract fun zipFile(src: ScriptFile, dest: ScriptFile, comment: String?): Result

将指定的源文件或目录压缩成一个 ZIP 文件.