11.23.10 • Published 10 months ago

lite-ts-fs v11.23.10

Weekly downloads
-
License
GPL-3.0
Repository
-
Last release
10 months ago

Version

代码

FileFactoryBase - 文件工厂

const fileFacotry: FileFactoryBase;
const paths: string[];
// paths = [a,b,c]

const dir = fileFacotry.buildDirectory(...paths);
// dir = IDirectory;

const file = fileFacotry.buildFile(...paths);
// file = IFile;
  • FsFileFactory - 文件系统文件工厂
const fileFactory: FileFactoryBase = new FsFileFactory();

FsFile(IFile) - 文件

const file: IFile;
// 示例文本内容"{'a':'b','c':'d'}"
const res = await file.read<{[key:string]:string}>();
// res = {"a":"b","c":"d"};

// 示例内容
// Default:
//    port: 3000
const res = await file.readYaml();
// res = { Default: { port: 3000 } };

// 删除文件
await file.remove();

// 示例文本内容"{'a':'b','c':'d'}"
await file.write(res + '2131');
// res = "{'a':'b','c':'d'}2131";

// bFile内容: '12345'
const bFile: IFile;
const opt: {
    paths: stirng;
    isForce?: boolean;
}
await file.copyTo(opt);
const res = await bFile.readString();
// res = "{'a':'b','c':'d'}2131";

const cFile: IFile;
const res = await cFile.exists();
// res = false;
const res = await cFile.readString();
// res = '';
await bFile.moveTo(cFile.path);
const res = await cFile.readString();
// res = "{'a':'b','c':'d'}2131";

FsDirectory(IDirectory) - 目录

const directory: IDirectory;
const res = await directory.exists();
// res = boolean;

// 创建目录 recursive:boolean-> 是否递归创建路径
const recursive: boolean;
await directory.create(recursive);

const subDirectorys = await directory.findDirectories();
// subDirectorys = IDirectory[];

const files = await directory.findFiles();
// files = IFile[]

// 删除目录
await directory.remove();

// 当目标文件存在时,如果 opts.isForce = true 是则覆盖,否则抛出异常
type opt = {
    path:string[],
    isForce?: boolean
};
await directory.copyTo(opt);

// 移动目录
const bDirectory: IDirectory;
await directory.moveTo(bDirectory);

// 查询目录内容
const res = await directory.read();
// res: string[] 目录名列表
11.14.8

11 months ago

11.13.8

11 months ago

11.16.8

11 months ago

11.15.8

11 months ago

11.18.8

11 months ago

11.17.8

11 months ago

11.23.10

10 months ago

11.21.8

11 months ago

11.20.8

11 months ago

11.23.8

10 months ago

11.22.8

10 months ago

11.23.9

10 months ago

11.19.8

11 months ago

11.12.8

1 year ago

11.12.7

1 year ago

11.11.7

2 years ago

11.11.6

2 years ago

1.11.6

2 years ago

3.11.6

2 years ago

1.10.6

2 years ago

1.10.5

2 years ago

1.10.4

2 years ago

1.10.3

2 years ago

1.10.2

2 years ago

1.9.2

2 years ago

1.9.1

2 years ago

1.8.1

2 years ago

1.7.1

2 years ago

1.6.1

2 years ago

1.5.1

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago