xrootd 0.1.6

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.
@@ -0,0 +1,454 @@
1
+ import { Readable, Writable } from "node:stream";
2
+
3
+ //#region lib/types.d.ts
4
+ type PropertyList = Record<string, string | number | boolean>;
5
+ interface IXRootDError extends Error {
6
+ xrdStatus: number;
7
+ xrdCode: number;
8
+ xrdErrNo: number;
9
+ xrdErrMsg: string;
10
+ }
11
+ interface StatInfo {
12
+ id: string;
13
+ size: bigint;
14
+ flags: number;
15
+ modTime: number;
16
+ accessTime: number;
17
+ changeTime: number;
18
+ modTimeAsString: string;
19
+ accessTimeAsString: string;
20
+ changeTimeAsString: string;
21
+ modeAsString: string;
22
+ modeAsOctString: string;
23
+ owner: string;
24
+ group: string;
25
+ checksum: string;
26
+ get modeOctal(): string;
27
+ get modeString(): string;
28
+ get isFile(): boolean;
29
+ get isDir(): boolean;
30
+ get isOther(): boolean;
31
+ get isOffline(): boolean;
32
+ get isPOSCPending(): boolean;
33
+ get isReadable(): boolean;
34
+ get isWritable(): boolean;
35
+ get isBackUpExists(): boolean;
36
+ }
37
+ interface LocationInfo {
38
+ address: string;
39
+ type: number;
40
+ accessType: number;
41
+ }
42
+ interface ReadChunkRequest {
43
+ offset: bigint | number;
44
+ size: number;
45
+ }
46
+ interface StatVFSInfo {
47
+ nodesRW: bigint;
48
+ freeRW: bigint;
49
+ utilizationRW: number;
50
+ nodesStaging: bigint;
51
+ freeStaging: bigint;
52
+ utilizationStaging: number;
53
+ }
54
+ interface DirListEntry {
55
+ name: string;
56
+ hostAddress: string;
57
+ stat: StatInfo | null;
58
+ }
59
+ interface XAttrStatusResult {
60
+ name: string;
61
+ isOk: boolean;
62
+ code: number;
63
+ message: string;
64
+ }
65
+ declare class XRootDError extends Error {
66
+ code: number;
67
+ status: number;
68
+ constructor(status: IXRootDError);
69
+ }
70
+ /**
71
+ * 对应 src/core/XrdNodeFile.cc 中 Init 暴露的类
72
+ */
73
+ interface INativeFile {
74
+ Open(url: string, flags: number, mode: number): Promise<void>;
75
+ Close(): Promise<void>;
76
+ Stat(): Promise<StatInfo>;
77
+ Read(offset: bigint, size: number): Promise<Buffer>;
78
+ Write(offset: bigint, buffer: Buffer): Promise<void>;
79
+ Sync(): Promise<void>;
80
+ Truncate(size: bigint): Promise<void>;
81
+ IsOpen(): boolean;
82
+ GetProperty(name: string): {
83
+ success: boolean;
84
+ value: string;
85
+ };
86
+ SetProperty(name: string, value: string): boolean;
87
+ VectorRead(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
88
+ ReadChunks(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
89
+ SetXAttr(attrs: Record<string, string>): Promise<XAttrStatusResult[]>;
90
+ GetXAttr(keys: string[]): Promise<Record<string, string>>;
91
+ DelXAttr(keys: string[]): Promise<XAttrStatusResult[]>;
92
+ ListXAttr(): Promise<Record<string, string>>;
93
+ Clone(list: CloneLocationRequest[]): Promise<void>;
94
+ }
95
+ interface ReadStreamOptions {
96
+ start?: bigint;
97
+ end?: bigint;
98
+ /**
99
+ * 每次从底层读取的块大小 (默认 64KB)
100
+ */
101
+ highWaterMark?: number;
102
+ }
103
+ interface WriteStreamOptions {
104
+ start?: bigint;
105
+ }
106
+ interface CloneLocationRequest {
107
+ srcFile: File;
108
+ dstOffset: bigint | number;
109
+ srcOffset: bigint | number;
110
+ length: bigint | number;
111
+ }
112
+ //#endregion
113
+ //#region lib/enums.d.ts
114
+ /**
115
+ * XrdCl::OpenFlags - 文件打开选项
116
+ * @see src/XProtocol/XProtocol.hh:XOpenRequestOption
117
+ * @see src/XrdCl/XrdClFileSystem.hh:OpenFlags::Flags
118
+ */
119
+ declare const OpenFlags: {
120
+ readonly None: 0;
121
+ readonly Compress: 1;
122
+ readonly Delete: 2;
123
+ readonly Force: 4;
124
+ readonly New: 8;
125
+ readonly Read: 16;
126
+ readonly Update: 32;
127
+ readonly Refresh: 128;
128
+ readonly MakePath: 256;
129
+ readonly IntentDirList: 1024;
130
+ readonly Replica: 2048;
131
+ readonly POSC: 4096;
132
+ readonly NoWait: 8192;
133
+ readonly SeqIO: 16384;
134
+ readonly Write: 32768;
135
+ readonly PrefName: 256;
136
+ readonly Dup: 65536;
137
+ readonly Samefs: 131072;
138
+ };
139
+ type OpenFlags = typeof OpenFlags[keyof typeof OpenFlags];
140
+ /**
141
+ * XrdCl::Access - 文件访问权限模式
142
+ * @see src/XProtocol/XProtocol.hh:XOpenRequestMode
143
+ * @see src/XrdCl/XrdClFileSystem.hh:Access::Mode
144
+ */
145
+ declare const AccessMode: {
146
+ readonly None: 0;
147
+ readonly UR: 256;
148
+ readonly UW: 128;
149
+ readonly UX: 64;
150
+ readonly GR: 32;
151
+ readonly GW: 16;
152
+ readonly GX: 8;
153
+ readonly OR: 4;
154
+ readonly OW: 2;
155
+ readonly OX: 1;
156
+ };
157
+ type AccessMode = number;
158
+ /**
159
+ * XrdCl::MkDirFlags - 目录创建选项
160
+ * @see src/XrdCl/XrdClFileSystem.hh:MkDirFlags::Flags
161
+ */
162
+ declare const MkDirFlags: {
163
+ readonly None: 0;
164
+ readonly MakePath: 1;
165
+ };
166
+ type MkDirFlags = typeof MkDirFlags[keyof typeof MkDirFlags];
167
+ //#endregion
168
+ //#region lib/file.d.ts
169
+ /**
170
+ * XRootD File 客户端
171
+ * 提供对远程文件的异步读写操作及 Node.js 风格的流式接口。
172
+ */
173
+ declare class File$1 {
174
+ private _internal;
175
+ constructor(internalInstance?: INativeFile);
176
+ /**
177
+ * 打开远程文件
178
+ * @param url 目标地址 (如 root://server//path/to/file)
179
+ * @param flags 打开标志位
180
+ * @param mode 访问权限模式
181
+ */
182
+ open(url: string, flags?: OpenFlags, mode?: AccessMode): Promise<void>;
183
+ /**
184
+ * 关闭文件
185
+ */
186
+ close(): Promise<void>;
187
+ /**
188
+ * 获取文件状态
189
+ */
190
+ stat(): Promise<StatInfo>;
191
+ /**
192
+ * 读取文件块 (Zero-Copy from C++)
193
+ * @param offset 偏移量 (支持 >2GB)
194
+ * @param size 读取字节数
195
+ * @returns 包含数据的 Node.js Buffer
196
+ */
197
+ read(offset: bigint | number, size: number): Promise<Buffer>;
198
+ /**
199
+ * 写入文件块
200
+ * @param offset 偏移量
201
+ * @param buffer 要写入的数据
202
+ */
203
+ write(offset: bigint | number, buffer: Buffer): Promise<void>;
204
+ /**
205
+ * 同步文件缓冲区到磁盘
206
+ */
207
+ sync(): Promise<void>;
208
+ /**
209
+ * 截断文件
210
+ * @param size 目标大小
211
+ */
212
+ truncate(size: bigint | number): Promise<void>;
213
+ /**
214
+ * 检查本地实例状态 (同步操作)
215
+ */
216
+ isOpen(): boolean;
217
+ getProperty(name: string): Promise<string>;
218
+ setProperty(name: string, value: string): Promise<void>;
219
+ /**
220
+ * 向量化读取 (Vector Read)
221
+ * 在单个请求中从文件的多个非连续区域读取数据,极大地减少网络往返开销。
222
+ * @param chunks 包含 offset 和 size 的读取请求数组
223
+ * @returns 与请求数组顺序对应的 Buffer 数组
224
+ */
225
+ vectorRead(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
226
+ /**
227
+ * 读取块 (Read Chunks)
228
+ * 类似于 VectorRead,但底层实现可能利用更高级的预读或多路复用策略。
229
+ */
230
+ readChunks(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
231
+ /**
232
+ * 设置文件的扩展属性
233
+ */
234
+ setXAttr(name: string, value: string): Promise<void>;
235
+ /**
236
+ * 获取文件的扩展属性
237
+ */
238
+ getXAttr(name: string): Promise<string>;
239
+ /**
240
+ * 删除文件的扩展属性
241
+ */
242
+ delXAttr(name: string): Promise<void>;
243
+ /**
244
+ * 列出文件所有的扩展属性名称
245
+ */
246
+ listXAttr(): Promise<string[]>;
247
+ /**
248
+ * 将其他文件的指定区间在服务器端克隆到当前文件
249
+ * 当前文件必须以写入/更新模式打开
250
+ */
251
+ clone(locations: CloneLocationRequest[]): Promise<void>;
252
+ /**
253
+ * 创建一个可读流 (Readable Stream)
254
+ * 使得 XRootD 文件可以无缝 pipe 到其他 Node.js 流 (如本地 fs, HTTP response)
255
+ */
256
+ createReadStream(options?: ReadStreamOptions): Readable;
257
+ /**
258
+ * 创建一个可写流 (Writable Stream)
259
+ * 支持通过 pipe 将大量数据流式写入 XRootD 服务器
260
+ */
261
+ createWriteStream(options?: WriteStreamOptions): Writable;
262
+ }
263
+ //#endregion
264
+ //#region lib/filesystem.d.ts
265
+ /**
266
+ * XRootD FileSystem 客户端
267
+ * 提供对远程服务器目录和文件的通用管理操作。
268
+ */
269
+ declare class FileSystem {
270
+ private _internal;
271
+ readonly serverUrl: string;
272
+ /**
273
+ * 实例化一个 FileSystem 客户端
274
+ * @param url 服务器地址 (例如: 'root://eospublic.cern.ch')
275
+ */
276
+ constructor(url: string);
277
+ /**
278
+ * 内部辅助方法:确保路径是标准的 Unix 绝对路径
279
+ */
280
+ private _normalize;
281
+ /**
282
+ * 定位文件在集群中的具体数据节点
283
+ * @param filePath 目标文件路径
284
+ * @param flags 定位标志位 (默认 0)
285
+ * @returns 包含主机、端口等信息的数组
286
+ */
287
+ locate(filePath: string, flags?: number): Promise<LocationInfo[]>;
288
+ /**
289
+ * 获取文件或目录的状态信息
290
+ * @param targetPath 目标路径
291
+ */
292
+ stat(targetPath: string): Promise<StatInfo>;
293
+ /**
294
+ * 删除远程文件
295
+ * @param filePath 要删除的文件路径
296
+ */
297
+ rm(filePath: string): Promise<void>;
298
+ /**
299
+ * 创建远程目录
300
+ * @param dirPath 目录路径
301
+ * @param flags 标志位 (例如 MakePath,允许创建多级父目录)
302
+ * @param mode 访问权限模式 (默认 0755 对应的 AccessMode)
303
+ */
304
+ mkdir(dirPath: string, flags?: MkDirFlags, mode?: AccessMode): Promise<void>;
305
+ /**
306
+ * 删除远程目录 (目录必须为空)
307
+ * @param dirPath 要删除的目录路径
308
+ */
309
+ rmdir(dirPath: string): Promise<void>;
310
+ /**
311
+ * 移动或重命名文件/目录
312
+ * @param source 源路径
313
+ * @param dest 目标路径
314
+ */
315
+ mv(source: string, dest: string): Promise<void>;
316
+ /**
317
+ * 列出目录下的所有文件和子目录名
318
+ * @param dirPath 目录路径
319
+ * @param flags 标志位 (例如是否显示隐藏文件)
320
+ */
321
+ dirList(dirPath: string, flags?: number): Promise<DirListEntry[]>;
322
+ /**
323
+ * 检查文件或目录是否存在
324
+ * (通过捕获 stat 的错误来实现,类似于老版本 Node 的 fs.exists)
325
+ * @param targetPath 目标路径
326
+ */
327
+ exists(targetPath: string): Promise<boolean>;
328
+ /**
329
+ * 确保目录存在。如果目录不存在,则会自动创建它及其所有父目录。
330
+ * (类似于 fs-extra 的 ensureDir 或 mkdir -p)
331
+ * @param dirPath 目标目录
332
+ */
333
+ ensureDir(dirPath: string): Promise<void>;
334
+ /**
335
+ * 深度定位:返回包含所有数据节点副本的详细物理位置信息
336
+ */
337
+ deepLocate(filePath: string, flags?: number): Promise<LocationInfo[]>;
338
+ /**
339
+ * 在不打开文件的情况下,直接截断目标文件
340
+ */
341
+ truncate(filePath: string, size: bigint | number): Promise<void>;
342
+ /**
343
+ * 更改远程文件或目录的访问权限
344
+ */
345
+ chmod(targetPath: string, mode: AccessMode): Promise<void>;
346
+ /**
347
+ * 探活:检查远端文件系统服务是否响应
348
+ */
349
+ ping(): Promise<void>;
350
+ /**
351
+ * 获取虚拟文件系统(VFS)的状态(如磁盘总容量、剩余可用空间)
352
+ */
353
+ statVFS(targetPath: string): Promise<StatVFSInfo>;
354
+ /**
355
+ * 获取当前连接协议的详细属性
356
+ */
357
+ protocol(): Promise<PropertyList>;
358
+ /**
359
+ * 发送带外查询指令到数据节点 (通常用于 XRootD 的高级自定义插件)
360
+ */
361
+ query(queryCode: number, args: Buffer): Promise<Buffer>;
362
+ /**
363
+ * 发送通用信息到服务器
364
+ */
365
+ sendInfo(info: string): Promise<Buffer>;
366
+ /**
367
+ * 发送缓存操作信息给集群
368
+ */
369
+ sendCache(info: string): Promise<Buffer>;
370
+ /**
371
+ * 数据预热/暂存 (Staging):
372
+ * 在处理海量物理数据时,通知存储集群将特定的冷数据(如磁带上的文件)提前拉取到磁盘缓存。
373
+ * @param targetPaths 需要预热的路径数组
374
+ * @param flags 预热策略标志
375
+ * @param priority 优先级
376
+ */
377
+ prepare(targetPaths: string[], flags?: number, priority?: number): Promise<Buffer>;
378
+ /**
379
+ * 获取文件系统属性
380
+ */
381
+ getProperty(name: string): {
382
+ success: boolean;
383
+ value: string;
384
+ };
385
+ /**
386
+ * 设置文件系统属性
387
+ */
388
+ setProperty(name: string, value: string): boolean;
389
+ /**
390
+ * 设置扩展属性
391
+ * @param targetPath 目标路径
392
+ * @param attrs 扩展属性键值对记录
393
+ */
394
+ setXAttr(targetPath: string, attrs: Record<string, string>): Promise<XAttrStatusResult[]>;
395
+ /**
396
+ * 获取扩展属性
397
+ * @param targetPath 目标路径
398
+ * @param keys 需要获取的属性名数组
399
+ */
400
+ getXAttr(targetPath: string, keys: string[]): Promise<Record<string, string>>;
401
+ /**
402
+ * 删除指定的扩展属性
403
+ * @param targetPath 目标路径
404
+ * @param keys 需要删除的属性名数组
405
+ */
406
+ delXAttr(targetPath: string, keys: string[]): Promise<XAttrStatusResult[]>;
407
+ /**
408
+ * 列出目标文件或目录的所有扩展属性
409
+ */
410
+ listXAttr(targetPath: string): Promise<Record<string, string>>;
411
+ }
412
+ //#endregion
413
+ //#region lib/url.d.ts
414
+ /**
415
+ * 纯 TypeScript 实现的 XRootD URL 解析器
416
+ * 安全、轻量,避免跨越 C++ N-API 边界
417
+ */
418
+ declare class XRootDUrl {
419
+ private _url;
420
+ readonly isValid: boolean;
421
+ constructor(urlString: string);
422
+ get protocol(): string;
423
+ set protocol(protocol: string);
424
+ get hostName(): string;
425
+ set hostName(hostName: string);
426
+ get port(): number;
427
+ set port(port: number | string);
428
+ get userName(): string;
429
+ set userName(userName: string);
430
+ get password(): string;
431
+ set password(password: string);
432
+ get hostId(): string;
433
+ set pathWithParams(path: string);
434
+ get pathWithParams(): string;
435
+ set searchParams(params: string);
436
+ get searchParams(): string;
437
+ set anchor(anchor: string);
438
+ get anchor(): string;
439
+ set path(path: string);
440
+ get path(): string;
441
+ getParams(): Record<string, string>;
442
+ toString(): string;
443
+ static isValid(urlString: string): boolean;
444
+ }
445
+ //#endregion
446
+ //#region lib/env.d.ts
447
+ declare const Env: {
448
+ readonly putInt: (key: string, value: number) => void;
449
+ readonly putString: (key: string, value: string) => void;
450
+ readonly getInt: (key: string) => number | null;
451
+ readonly getString: (key: string) => string | null;
452
+ };
453
+ //#endregion
454
+ export { AccessMode, Env, File$1 as File, FileSystem, type LocationInfo, MkDirFlags, OpenFlags, type PropertyList, type ReadChunkRequest, type ReadStreamOptions, type StatInfo, type StatVFSInfo, XRootDUrl as URL, type WriteStreamOptions, type XRootDError };