fsd 0.11.0 → 0.13.0
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/index.d.ts +148 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -18,8 +18,25 @@ export interface FileMetadata {
|
|
|
18
18
|
lastModified?: Date;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 创建URL选项
|
|
23
|
+
*/
|
|
21
24
|
export interface CreateUrlOptions {
|
|
25
|
+
/**
|
|
26
|
+
* 文件路径,可选,适用于VOD驱动获取不同清晰度的视频播放地址
|
|
27
|
+
*/
|
|
28
|
+
path?: string;
|
|
29
|
+
/**
|
|
30
|
+
* 缩略图规格名
|
|
31
|
+
*/
|
|
32
|
+
thumb?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 链接过期时间,单位秒,默认值 3600
|
|
35
|
+
*/
|
|
22
36
|
expires?: number;
|
|
37
|
+
/**
|
|
38
|
+
* 链接响应头,可选
|
|
39
|
+
*/
|
|
23
40
|
response?: {
|
|
24
41
|
'content-type'?: string;
|
|
25
42
|
'content-disposition'?: string;
|
|
@@ -33,43 +50,170 @@ export interface WithPromise {
|
|
|
33
50
|
export type Task = string;
|
|
34
51
|
export type Part = string;
|
|
35
52
|
|
|
53
|
+
/**
|
|
54
|
+
* 文件对象
|
|
55
|
+
*/
|
|
36
56
|
export interface FSDFile {
|
|
57
|
+
/**
|
|
58
|
+
* 是否为FSDFile实例
|
|
59
|
+
*/
|
|
37
60
|
readonly instanceOfFSDFile: true;
|
|
61
|
+
/**
|
|
62
|
+
* 文件路径,例如 /path/to/file.txt
|
|
63
|
+
*/
|
|
38
64
|
readonly path: string;
|
|
65
|
+
/**
|
|
66
|
+
* 文件所在目录,例如 /path/to
|
|
67
|
+
*/
|
|
39
68
|
readonly dir: string;
|
|
69
|
+
/**
|
|
70
|
+
* 文件名,包含扩展名,例如 file.txt
|
|
71
|
+
*/
|
|
40
72
|
readonly base: string;
|
|
73
|
+
/**
|
|
74
|
+
* 文件名,不包含扩展名,例如 file
|
|
75
|
+
*/
|
|
41
76
|
readonly name: string;
|
|
77
|
+
/**
|
|
78
|
+
* 文件扩展名,例如 .txt
|
|
79
|
+
*/
|
|
42
80
|
readonly ext: string;
|
|
81
|
+
/**
|
|
82
|
+
* 是否需要确保目录存在
|
|
83
|
+
*/
|
|
43
84
|
readonly needEnsureDir: boolean;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 给文件追加内容
|
|
88
|
+
* @param {string|Buffer|NodeJS.ReadableStream} data 追加内容
|
|
89
|
+
*/
|
|
44
90
|
append(data: string | Buffer | NodeJS.ReadableStream): Promise<void>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 读取文件内容
|
|
94
|
+
* @param {string} [encoding] 编码
|
|
95
|
+
*/
|
|
45
96
|
read(encoding: BufferEncoding): Promise<string>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 读取文件内容
|
|
100
|
+
* @param {number} [position] 读取起始位置
|
|
101
|
+
* @param {number} [length] 读取长度
|
|
102
|
+
*/
|
|
46
103
|
read(position?: number, length?: number): Promise<Buffer>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 读取文件内容
|
|
107
|
+
* @param {number} position 读取起始位置
|
|
108
|
+
* @param {number} length 读取长度
|
|
109
|
+
* @param {string} encoding 编码
|
|
110
|
+
*/
|
|
47
111
|
read(position: number, length: number, encoding: BufferEncoding): Promise<string>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 写入文件内容
|
|
115
|
+
* @param {string|Buffer|NodeJS.ReadableStream} [data] 写入内容
|
|
116
|
+
*/
|
|
48
117
|
write(data?: string | Buffer | NodeJS.ReadableStream): Promise<void>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 创建读取流
|
|
121
|
+
* @param {object} options 读取流选项
|
|
122
|
+
*/
|
|
49
123
|
createReadStream(options?: ReadStreamOptions): Promise<NodeJS.ReadableStream>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 创建写入流
|
|
127
|
+
* @param {object} options 写入流选项
|
|
128
|
+
*/
|
|
50
129
|
createWriteStream(options?: WriteStreamOptions): Promise<NodeJS.WritableStream>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 删除文件
|
|
133
|
+
*/
|
|
51
134
|
unlink(): Promise<void>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 新建目录
|
|
138
|
+
* @param {boolean} [recursive] 是否递归创建
|
|
139
|
+
*/
|
|
52
140
|
mkdir(recursive?: boolean): Promise<void>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 读取目录
|
|
144
|
+
* @param {boolean|string} [recursion] 是否递归读取,或者指定子目录glob规则
|
|
145
|
+
*/
|
|
53
146
|
readdir(recursion?: true | string): Promise<FSDFile[]>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 创建访问URL
|
|
150
|
+
* @param {object} options 创建URL选项
|
|
151
|
+
*/
|
|
54
152
|
createUrl(options?: CreateUrlOptions): Promise<string>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 拷贝文件到目标路径
|
|
156
|
+
* @param {string} dest 目标路径
|
|
157
|
+
*/
|
|
55
158
|
copy(dest: string): Promise<FSDFile>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 重命名文件到目标路径
|
|
162
|
+
* @param {string} dest 目标路径
|
|
163
|
+
*/
|
|
56
164
|
rename(dest: string): Promise<void>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 判断文件是否存在
|
|
168
|
+
*/
|
|
57
169
|
exists(): Promise<boolean>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 判断文件是否为文件
|
|
173
|
+
*/
|
|
58
174
|
isFile(): Promise<boolean>;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 判断文件是否为目录
|
|
178
|
+
*/
|
|
59
179
|
isDirectory(): Promise<boolean>;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 获取文件大小
|
|
183
|
+
*/
|
|
60
184
|
size(): Promise<number>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 获取文件最后修改时间
|
|
188
|
+
*/
|
|
61
189
|
lastModified(): Promise<Date>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 创建分片上传任务
|
|
193
|
+
* @param {number} partCount 分片数量
|
|
194
|
+
*/
|
|
62
195
|
initMultipartUpload(partCount: number): Promise<Task[]>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 上传分片数据
|
|
199
|
+
* @param {string} partTask 分片任务ID
|
|
200
|
+
* @param {any} data 分片数据
|
|
201
|
+
* @param {number} [size] 分片大小
|
|
202
|
+
*/
|
|
63
203
|
writePart(
|
|
64
204
|
partTask: Task,
|
|
65
205
|
data: string | Buffer | NodeJS.ReadableStream,
|
|
66
206
|
size?: number
|
|
67
207
|
): Promise<Part>;
|
|
68
208
|
completeMultipartUpload(parts: Part[]): Promise<void>;
|
|
209
|
+
|
|
69
210
|
toString(): string;
|
|
70
211
|
toJSON(): string;
|
|
71
212
|
}
|
|
72
213
|
|
|
214
|
+
/**
|
|
215
|
+
* 文件分片选项
|
|
216
|
+
*/
|
|
73
217
|
export interface AllocOptions {
|
|
74
218
|
path?: string;
|
|
75
219
|
name?: string;
|
|
@@ -92,8 +236,11 @@ export class Adapter<T> {
|
|
|
92
236
|
alloc?: (options?: AllocOptions) => Promise<string>;
|
|
93
237
|
/**
|
|
94
238
|
* 创建上传凭证,如果支持边缘上传,否则不存在
|
|
239
|
+
* @param path 文件路径
|
|
240
|
+
* @param {any} [meta] 文件元数据
|
|
241
|
+
* @param {number} [durationSeconds] 令牌有效时长,单位秒
|
|
95
242
|
*/
|
|
96
|
-
createUploadToken?: (path: string, meta?: any) => Promise<any>;
|
|
243
|
+
createUploadToken?: (path: string, meta?: any, durationSeconds?: number) => Promise<any>;
|
|
97
244
|
|
|
98
245
|
constructor(options: T);
|
|
99
246
|
append(path: string, data: string | Buffer | NodeJS.ReadableStream): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fsd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "General file system driver for Node.js",
|
|
5
5
|
"main": "lib/fsd.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"is-stream": "^2.0.1",
|
|
17
17
|
"slash": "^3.0.0"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "1548128573c0fd22977706a6704029ec3ca3bab6"
|
|
20
20
|
}
|