内置模块
为方便插件开发者使用,Serein按照NodeJs的风格内置了一些基本的函数
所有模块已默认导入到上下文中,所以你可以直接使用
fs
示例
fs.writeFileSync("1.txt", "Hello, World!");
fs.copyFileSync("1.txt", "2.txt");
注意
因懒得实现,所有Buffer
类Buffer
均使用integer[]
代替,方便内部.NET代码转换- 只实现了部分同步函数,剩余的函数可能在未来补全
- 没有进行过严格的测试,其行为可能和NodeJs中的存在差异
appendFileSync(path: string, data: string, options?: string | object): void
appendFileSync(path: string, data: integer[], options?: string | object): void
closeSync(fd: integer): void
copyFileSync(src: string, dest: string, flags: integer = 0): void
flags != 1
时会覆盖原有文件(如果存在)
existsSync(path: string): boolean
fsyncSync(fd: integer)
ftruncateSync(fd: integer, len: integer = 0): void
futimesSync(fd: integer, atime: Date, mtime: Date): void
globSync(pattern: string, options?: object): string
globSync(pattern: string[], options?: object): string
mkdirSync(path: string, options?: object): void
options.mode
仅在非Windows平台上生效,这与NodeJs中一致,下同
mkdirSync(path: string, options?: integer = 0o777): void
mkdtempSync(prefix: string, options?: object): string
openSync(path: string, flags: string, mode?: string | integer): integer
mode
总是会被忽略
readdirSync(path: string, options?: object): string[]
- 仅有
options.recursive
会生效
- 仅有
readFileSync(path: string, options?: object): string
readSync(fd: integet, buffer: integer[], offset: integer, length: integer, position: integer = 0): integer
renameSync(oldPath: string, newPath: string): void
rmdirSync(path: string, options?: object): void
- 仅有
options.recursive
会生效
- 仅有
rmSync(path: string, options?: object): void
- 仅有
options.recursive
会生效
- 仅有
symlinkSync(target: string, path: string, type?: string): void
type
总是会被忽略
truncateSync(path: string, len: integer = 0): void
unlinkSync(path: string): void
- 实际上是删除
path
- 实际上是删除
utimesSync(path: string, atime: Date, mtime: Date): void
writeFileSync(path: string, data: string, options?: string | object): void
writeFileSync(path: string, data: integer[], options?: string | object): void
writeSync(fd: integer, buffer: integer[], offset: integer, length: integer, position: integer): integer
writeSync(fd: integer, data: string, position: integer = 0, encoding: string = 'utf8'): integer
process
arch: string
- 实际上只会返回"x64"或"arm64",这是因为Serein的发行版没有x86的构建(
argv: string[]
argv0: string
- 即
argv[0]
- 即
chdir(directory: string): string
- 不推荐使用此函数,否则可能导致文件错位
cwd(): string
exit(code: integer = 0): void
- 不推荐使用此函数
env: { [key: string]: string }
execPath: string
exitCode: integer
kill(pid: integer)
pid: integer
platform: string
- 实际上仅会返回
win32nt
、unix
或other
- 实际上仅会返回
version: string
- 返回的是.NET运行时版本