xrootd 0.2.3 → 1.0.0-beta.2

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +189 -0
  3. package/README.md +334 -101
  4. package/dist/index.d.mts +620 -821
  5. package/dist/index.mjs +1554 -723
  6. package/package.json +64 -83
  7. package/LICENSE-GPLv3 +0 -674
  8. package/LICENSE-MIT +0 -7
  9. package/dist/index.cjs +0 -817
  10. package/dist/index.d.cts +0 -864
  11. package/libs/darwin-arm64/libXrdCl.6.dylib +0 -0
  12. package/libs/darwin-arm64/libXrdCrypto.6.dylib +0 -0
  13. package/libs/darwin-arm64/libXrdCryptossl-6.so +0 -0
  14. package/libs/darwin-arm64/libXrdSec-6.so +0 -0
  15. package/libs/darwin-arm64/libXrdSecProt-6.so +0 -0
  16. package/libs/darwin-arm64/libXrdSeckrb5-6.so +0 -0
  17. package/libs/darwin-arm64/libXrdSecpwd-6.so +0 -0
  18. package/libs/darwin-arm64/libXrdSecsss-6.so +0 -0
  19. package/libs/darwin-arm64/libXrdSecunix-6.so +0 -0
  20. package/libs/darwin-arm64/libXrdSecztn-6.so +0 -0
  21. package/libs/darwin-arm64/libXrdUtils.6.dylib +0 -0
  22. package/libs/darwin-arm64/libXrdXml.6.dylib +0 -0
  23. package/libs/darwin-x64/libXrdCl.6.dylib +0 -0
  24. package/libs/darwin-x64/libXrdCrypto.6.dylib +0 -0
  25. package/libs/darwin-x64/libXrdCryptossl-6.so +0 -0
  26. package/libs/darwin-x64/libXrdSec-6.so +0 -0
  27. package/libs/darwin-x64/libXrdSecProt-6.so +0 -0
  28. package/libs/darwin-x64/libXrdSeckrb5-6.so +0 -0
  29. package/libs/darwin-x64/libXrdSecpwd-6.so +0 -0
  30. package/libs/darwin-x64/libXrdSecsss-6.so +0 -0
  31. package/libs/darwin-x64/libXrdSecunix-6.so +0 -0
  32. package/libs/darwin-x64/libXrdSecztn-6.so +0 -0
  33. package/libs/darwin-x64/libXrdUtils.6.dylib +0 -0
  34. package/libs/darwin-x64/libXrdXml.6.dylib +0 -0
  35. package/libs/linux-arm64/libXrdCl.so.6 +0 -0
  36. package/libs/linux-arm64/libXrdCrypto.so.6 +0 -0
  37. package/libs/linux-arm64/libXrdCryptossl-6.so +0 -0
  38. package/libs/linux-arm64/libXrdSec-6.so +0 -0
  39. package/libs/linux-arm64/libXrdSecProt-6.so +0 -0
  40. package/libs/linux-arm64/libXrdSeckrb5-6.so +0 -0
  41. package/libs/linux-arm64/libXrdSecpwd-6.so +0 -0
  42. package/libs/linux-arm64/libXrdSecsss-6.so +0 -0
  43. package/libs/linux-arm64/libXrdSecunix-6.so +0 -0
  44. package/libs/linux-arm64/libXrdSecztn-6.so +0 -0
  45. package/libs/linux-arm64/libXrdUtils.so.6 +0 -0
  46. package/libs/linux-arm64/libXrdXml.so.6 +0 -0
  47. package/libs/linux-x64/libXrdCl.so.6 +0 -0
  48. package/libs/linux-x64/libXrdCrypto.so.6 +0 -0
  49. package/libs/linux-x64/libXrdCryptossl-6.so +0 -0
  50. package/libs/linux-x64/libXrdSec-6.so +0 -0
  51. package/libs/linux-x64/libXrdSecProt-6.so +0 -0
  52. package/libs/linux-x64/libXrdSeckrb5-6.so +0 -0
  53. package/libs/linux-x64/libXrdSecpwd-6.so +0 -0
  54. package/libs/linux-x64/libXrdSecsss-6.so +0 -0
  55. package/libs/linux-x64/libXrdSecunix-6.so +0 -0
  56. package/libs/linux-x64/libXrdSecztn-6.so +0 -0
  57. package/libs/linux-x64/libXrdUtils.so.6 +0 -0
  58. package/libs/linux-x64/libXrdXml.so.6 +0 -0
  59. package/prebuilds/darwin-arm64/xrootd.node +0 -0
  60. package/prebuilds/darwin-x64/xrootd.node +0 -0
  61. package/prebuilds/linux-arm64/xrootd.node +0 -0
  62. package/prebuilds/linux-x64/xrootd.node +0 -0
package/dist/index.d.mts CHANGED
@@ -1,864 +1,663 @@
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
- type XRootDOkError = {
12
- ok: true;
13
- } | ({
14
- ok: false;
15
- } & IXRootDError);
16
- type XAttrStatusResult = {
17
- ok: true;
18
- name: string;
19
- } | ({
20
- ok: false;
21
- name: string;
22
- } & IXRootDError);
23
- interface StatInfo {
24
- id: string;
25
- size: bigint;
26
- flags: number;
27
- modTime: number;
28
- accessTime: number;
29
- changeTime: number;
30
- modTimeAsString: string;
31
- accessTimeAsString: string;
32
- changeTimeAsString: string;
33
- modeAsString: string;
34
- modeAsOctString: string;
35
- owner: string;
36
- group: string;
37
- checksum: string;
38
- get modeOctal(): string;
39
- get modeString(): string;
40
- get isFile(): boolean;
41
- get isDir(): boolean;
42
- get isOther(): boolean;
43
- get isOffline(): boolean;
44
- get isPOSCPending(): boolean;
45
- get isReadable(): boolean;
46
- get isWritable(): boolean;
47
- get isBackUpExists(): boolean;
48
- }
49
- interface LocationInfo {
50
- address: string;
51
- type: number;
52
- accessType: number;
53
- }
54
- interface ReadChunkRequest {
55
- offset: bigint | number;
56
- size: number;
57
- }
58
- interface StatVFSInfo {
59
- nodesRW: bigint;
60
- freeRW: bigint;
61
- utilizationRW: number;
62
- nodesStaging: bigint;
63
- freeStaging: bigint;
64
- utilizationStaging: number;
65
- }
66
- interface DirListEntry {
67
- name: string;
68
- hostAddress: string;
69
- stat: StatInfo | null;
1
+ //#region src/transport/interface.d.ts
2
+ interface ITransport {
3
+ connect(host: string, port: number, useTls?: boolean): Promise<void>;
4
+ send(data: Buffer): Promise<void>;
5
+ onData(callback: (chunk: Buffer) => void): void;
6
+ removeDataHandler(callback: (chunk: Buffer) => void): void;
7
+ onClose(callback: () => void): void;
8
+ onError(callback: (err: Error) => void): void;
9
+ close(): Promise<void>;
10
+ destroy(): void;
70
11
  }
71
- declare class XRootDError extends Error {
72
- code: number;
12
+ //#endregion
13
+ //#region src/transport/framer.d.ts
14
+ /** Complete XRootD response frame */
15
+ interface Frame {
16
+ streamId: Buffer;
73
17
  status: number;
74
- constructor(status: XRootDOkError);
18
+ dlen: number;
19
+ body: Buffer;
75
20
  }
76
21
  /**
77
- * 对应 src/core/XrdNodeFile.cc Init 暴露的类
22
+ * Frame parser: handles TCP fragmentation, splits byte stream into complete XRootD response frames.
23
+ *
24
+ * XRootD response format:
25
+ * streamid[2] + status[2] + dlen[4] + body[dlen]
26
+ * Fixed header 8 bytes + variable body
78
27
  */
79
- interface INativeFile {
80
- Open(url: string, flags: number, mode: number): Promise<void>;
81
- Close(): Promise<void>;
82
- Stat(): Promise<StatInfo>;
83
- Read(offset: bigint, size: number): Promise<Buffer>;
84
- Write(offset: bigint, buffer: Buffer): Promise<void>;
85
- WriteFd(offset: bigint, size: number, fd: number, fdoff?: bigint): Promise<void>;
86
- Sync(): Promise<void>;
87
- Truncate(size: bigint): Promise<void>;
88
- IsOpen(): boolean;
89
- GetProperty(name: string): {
90
- success: boolean;
91
- value: string;
92
- };
93
- SetProperty(name: string, value: string): boolean;
94
- VectorRead(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
95
- ReadChunks(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
96
- SetXAttr(attrs: Record<string, string>): Promise<XAttrStatusResult[]>;
97
- GetXAttr(keys: string[]): Promise<Record<string, string>>;
98
- DelXAttr(keys: string[]): Promise<XAttrStatusResult[]>;
99
- ListXAttr(): Promise<Record<string, string>>;
100
- Clone(list: CloneLocationRequest[]): Promise<void>;
101
- }
102
- interface CopyJobConfig {
103
- /** original source URL */
104
- source: string;
105
- /** target directory or file */
106
- target: string;
107
- /** maximum number sources */
108
- sourceLimit?: number;
109
- /** overwrite target if exists */
110
- force?: boolean;
111
- /** persistify only on successful close */
112
- posc?: boolean;
113
- /** ignore locking semantics on destination */
114
- coerce?: boolean;
115
- /** create path to the file if it doesn't exist */
116
- makeDir?: boolean;
117
- /** "first" try third party copy, if it fails try normal copy; "only" only try third party copy */
118
- thirdParty?: string;
119
- /** "none" - no checksumming
120
- "end2end" - end to end checksumming
121
- "source" - calculate checksum at source
122
- "target" - calculate checksum at target */
123
- checkSumMode?: "none" | "end2end" | "source" | "target";
124
- /** type of the checksum to be used */
125
- checkSumType?: string;
126
- /** checksum preset */
127
- checkSumPreset?: string;
128
- /** size of a copy chunks in bytes */
129
- chunkSize?: number;
130
- /** number of chunks that should be requested in parallel
131
- *
132
- * [uint8_t]
133
- */
134
- parallelChunks?: number;
135
- /** time limit for successfull initialization of the copy job
136
- * [time_t]
137
- */
138
- initTimeout?: number;
139
- /** time limit for the actual copy to finish
140
- * [time_t]
141
- */
142
- tpcTimeout?: number;
143
- /** support for the case where the size source file may change during reading process */
144
- dynamicSource?: boolean;
28
+ declare class Framer {
29
+ private pending;
30
+ /** Feed raw bytes, return parsed complete frames (0 or more) */
31
+ feed(chunk: Buffer): Frame[];
145
32
  }
146
- interface CopyJobResult {
147
- /** checksum at source, if requested */
148
- sourceCheckSum?: string;
149
- /** checksum at target, if requested */
150
- targetCheckSum?: string;
151
- /** file size */
152
- size: bigint;
153
- /** status of the copy operation */
154
- status?: XRootDOkError;
155
- /** all sources used */
156
- sources?: string[];
157
- /** the actual disk server target */
158
- realTarget?: string;
33
+ //#endregion
34
+ //#region src/transport/multiplexer.d.ts
35
+ interface MultiplexerOptions {
36
+ maxRedirects?: number;
37
+ onRedirect?: (host: string, port: number) => Promise<void>;
159
38
  }
160
- type ProgressCallback = (jobNum: number, processed: number, total: number) => void;
161
- interface ReadStreamOptions {
162
- start?: bigint;
163
- end?: bigint;
164
- /**
165
- * 每次从底层读取的块大小 (默认 64KB)
166
- */
167
- highWaterMark?: number;
39
+ /**
40
+ * Layer 3 Multiplexer
41
+ *
42
+ * Maintains streamId → Promise mapping.
43
+ * Generates incremental stream IDs, stores pending requests in Map,
44
+ * resolves when Framer delivers matching response frames.
45
+ */
46
+ declare class Multiplexer {
47
+ private transport;
48
+ private framer;
49
+ private pending;
50
+ private nextStreamId;
51
+ private timeout;
52
+ private sweepTimer;
53
+ private closed;
54
+ private redirectCount;
55
+ private maxRedirects;
56
+ private onRedirect?;
57
+ constructor(transport: ITransport, options?: MultiplexerOptions);
58
+ private allocateStreamId;
59
+ request(requestId: number, body: Uint8Array, data?: Uint8Array): Promise<Frame>;
60
+ private handleFrame;
61
+ private handleWaitResponse;
62
+ private handleRedirectResponse;
63
+ private retryRequest;
64
+ private sweepTimeouts;
65
+ setTimeout(ms: number): void;
66
+ resetRedirectCount(): void;
67
+ getTransport(): ITransport;
68
+ close(): void;
69
+ private rejectAll;
168
70
  }
169
- interface WriteStreamOptions {
170
- start?: bigint;
71
+ //#endregion
72
+ //#region src/url/url.d.ts
73
+ declare class XRootDUrl {
74
+ protocol: string;
75
+ user?: string;
76
+ password?: string;
77
+ host: string;
78
+ port: number;
79
+ path: string;
80
+ constructor(url: string);
81
+ static parse(url: string): XRootDUrl;
82
+ toString(): string;
83
+ isValid(): boolean;
84
+ isSecure(): boolean;
85
+ getHostId(): string;
86
+ getChannelId(): string;
87
+ getLocation(): string;
88
+ private getAuthString;
171
89
  }
172
- interface CloneLocationRequest {
173
- srcFile: File;
174
- dstOffset: bigint | number;
175
- srcOffset: bigint | number;
176
- length: bigint | number;
90
+ //#endregion
91
+ //#region src/security/interface.d.ts
92
+ interface SecEntity {
93
+ prot: string;
94
+ name?: string;
95
+ host?: string;
96
+ uid: number;
97
+ gid: number;
177
98
  }
178
99
  //#endregion
179
- //#region lib/enums.d.ts
100
+ //#region src/session/handshake.d.ts
101
+ interface Session {
102
+ sessid: Uint8Array;
103
+ protocolVersion: number;
104
+ secReqs?: string;
105
+ bifReqs?: string;
106
+ secEntity?: SecEntity;
107
+ }
180
108
  /**
181
- * XrdCl::OpenFlags - 文件打开选项
182
- * @see src/XProtocol/XProtocol.hh:XOpenRequestOption
183
- * @see src/XrdCl/XrdClFileSystem.hh:OpenFlags::Flags
109
+ * Perform XRootD connection handshake:
110
+ * 1. Send ClientInitHandShake(20B) + kXR_protocol(24B) merged = 44 bytes
111
+ * 2. Receive handshake response frame (16B: ServerResponseHeader 8B with
112
+ * dlen/msglen shared with ServerInitHandShake)
113
+ * 3. Receive kXR_ok + Protocol Response
114
+ * 4. Send kXR_login request
115
+ * 5. Receive kXR_ok + Login Response (sessid[16] + optional secToken)
116
+ * 6. [Optional] kXR_auth multi-round authentication
184
117
  */
118
+ declare function handshake(mux: Multiplexer, url: XRootDUrl, options?: {
119
+ username?: string;
120
+ pid?: number;
121
+ }): Promise<Session>;
122
+ //#endregion
123
+ //#region src/protocol/constants.d.ts
124
+ declare const RequestId: {
125
+ readonly Auth: 3000;
126
+ readonly Query: 3001;
127
+ readonly Chmod: 3002;
128
+ readonly Close: 3003;
129
+ readonly Dirlist: 3004;
130
+ readonly Gpfile: 3005;
131
+ readonly Protocol: 3006;
132
+ readonly Login: 3007;
133
+ readonly Mkdir: 3008;
134
+ readonly Mv: 3009;
135
+ readonly Open: 3010;
136
+ readonly Ping: 3011;
137
+ readonly Chkpoint: 3012;
138
+ readonly Read: 3013;
139
+ readonly Rm: 3014;
140
+ readonly Rmdir: 3015;
141
+ readonly Sync: 3016;
142
+ readonly Stat: 3017;
143
+ readonly Set: 3018;
144
+ readonly Write: 3019;
145
+ readonly Fattr: 3020;
146
+ readonly Prepare: 3021;
147
+ readonly Statx: 3022;
148
+ readonly Endsess: 3023;
149
+ readonly Bind: 3024;
150
+ readonly ReadV: 3025;
151
+ readonly PgWrite: 3026;
152
+ readonly Locate: 3027;
153
+ readonly Truncate: 3028;
154
+ readonly Sigver: 3029;
155
+ readonly PgRead: 3030;
156
+ readonly WriteV: 3031;
157
+ readonly Clone: 3032;
158
+ };
159
+ type RequestId = typeof RequestId[keyof typeof RequestId];
160
+ declare const ResponseStatus: {
161
+ readonly Ok: 0;
162
+ readonly Oksofar: 4000;
163
+ readonly Attn: 4001;
164
+ readonly Authmore: 4002;
165
+ readonly Error: 4003;
166
+ readonly Redirect: 4004;
167
+ readonly Wait: 4005;
168
+ readonly Waitresp: 4006;
169
+ readonly Status: 4007;
170
+ };
171
+ type ResponseStatus = typeof ResponseStatus[keyof typeof ResponseStatus];
172
+ declare const ServerError: {
173
+ readonly ArgInvalid: 3000;
174
+ readonly ArgMissing: 3001;
175
+ readonly ArgTooLong: 3002;
176
+ readonly FileLocked: 3003;
177
+ readonly FileNotOpen: 3004;
178
+ readonly FSError: 3005;
179
+ readonly InvalidRequest: 3006;
180
+ readonly IOError: 3007;
181
+ readonly NoMemory: 3008;
182
+ readonly NoSpace: 3009;
183
+ readonly NotAuthorized: 3010;
184
+ readonly NotFound: 3011;
185
+ readonly ServerError: 3012;
186
+ readonly Unsupported: 3013;
187
+ readonly NoServer: 3014;
188
+ readonly NotFile: 3015;
189
+ readonly IsDirectory: 3016;
190
+ readonly Cancelled: 3017;
191
+ readonly ItExists: 3018;
192
+ readonly CheckSumErr: 3019;
193
+ readonly InProgress: 3020;
194
+ readonly OverQuota: 3021;
195
+ readonly SigVerErr: 3022;
196
+ readonly DecryptErr: 3023;
197
+ readonly Overloaded: 3024;
198
+ readonly FsReadOnly: 3025;
199
+ readonly BadPayload: 3026;
200
+ readonly AttrNotFound: 3027;
201
+ readonly TLSRequired: 3028;
202
+ readonly NoReplicas: 3029;
203
+ readonly AuthFailed: 3030;
204
+ readonly Impossible: 3031;
205
+ readonly Conflict: 3032;
206
+ readonly TooManyErrs: 3033;
207
+ readonly ReqTimedOut: 3034;
208
+ readonly TimerExpired: 3035;
209
+ };
210
+ type ServerError = typeof ServerError[keyof typeof ServerError];
211
+ declare const ClientError: {
212
+ readonly Ok: 0;
213
+ readonly InvalidArgs: 300;
214
+ readonly NotFound: 301;
215
+ readonly Permission: 302;
216
+ readonly Serialization: 303;
217
+ readonly CommandNotFound: 304;
218
+ readonly HostNotFound: 305;
219
+ readonly ServiceUnavail: 306;
220
+ readonly InternalError: 307;
221
+ readonly BadRequest: 308;
222
+ readonly Timeout: 309;
223
+ readonly InsufficientData: 310;
224
+ readonly Uninitialized: 311;
225
+ readonly Disconnected: 312;
226
+ readonly Redirect: 313;
227
+ readonly LossyRetry: 314;
228
+ readonly TooManyRedirs: 315;
229
+ readonly ChunkChecksumErr: 316;
230
+ readonly UnexpectedResp: 317;
231
+ readonly ClientSkipped: 318;
232
+ readonly Failed: 501;
233
+ readonly WinNetworkError: 601;
234
+ };
235
+ type ClientError = typeof ClientError[keyof typeof ClientError];
185
236
  declare const OpenFlags: {
186
- readonly None: 0;
187
- readonly Compress: 1;
237
+ readonly Read: 16;
238
+ readonly Write: 32;
239
+ readonly Append: 512;
240
+ readonly New: 8;
188
241
  readonly Delete: 2;
189
242
  readonly Force: 4;
190
- readonly New: 8;
191
- readonly Read: 16;
192
- readonly Update: 32;
243
+ readonly Compress: 1;
244
+ readonly Async: 64;
193
245
  readonly Refresh: 128;
194
- readonly MakePath: 256;
195
- readonly IntentDirList: 1024;
246
+ readonly Mkpath: 256;
247
+ readonly Retstat: 1024;
196
248
  readonly Replica: 2048;
197
- readonly POSC: 4096;
198
- readonly NoWait: 8192;
199
- readonly SeqIO: 16384;
200
- readonly Write: 32768;
201
- readonly PrefName: 256;
202
- readonly Dup: 65536;
203
- readonly Samefs: 131072;
249
+ readonly Posc: 4096;
250
+ readonly Nowait: 8192;
251
+ readonly Seqio: 16384;
252
+ readonly Wrto: 32768;
204
253
  };
205
254
  type OpenFlags = typeof OpenFlags[keyof typeof OpenFlags];
206
- /**
207
- * XrdCl::Access - 文件访问权限模式
208
- * @see src/XProtocol/XProtocol.hh:XOpenRequestMode
209
- * @see src/XrdCl/XrdClFileSystem.hh:Access::Mode
210
- */
211
- declare const AccessMode: {
212
- readonly None: 0;
213
- readonly UR: 256;
214
- readonly UW: 128;
215
- readonly UX: 64;
216
- readonly GR: 32;
217
- readonly GW: 16;
218
- readonly GX: 8;
219
- readonly OR: 4;
220
- readonly OW: 2;
221
- readonly OX: 1;
222
- };
223
- type AccessMode = number;
224
- /**
225
- * XrdCl::MkDirFlags - 目录创建选项
226
- * @see src/XrdCl/XrdClFileSystem.hh:MkDirFlags::Flags
227
- */
228
- declare const MkDirFlags: {
229
- readonly None: 0;
230
- readonly MakePath: 1;
255
+ declare const PROTOCOL_VERSION = 1312;
256
+ declare const REQUEST_HDR_SIZE = 24;
257
+ declare const RESPONSE_HDR_SIZE = 8;
258
+ declare const BODY_SIZE = 16;
259
+ declare const SESS_ID_SIZE = 16;
260
+ declare const FHANDLE_SIZE = 4;
261
+ declare const REQUEST_OFFSET_STREAM_ID = 0;
262
+ declare const REQUEST_OFFSET_REQUEST_ID = 2;
263
+ declare const REQUEST_OFFSET_BODY = 4;
264
+ declare const REQUEST_OFFSET_DLEN = 20;
265
+ declare const RESPONSE_OFFSET_STREAM_ID = 0;
266
+ declare const RESPONSE_OFFSET_STATUS = 2;
267
+ declare const RESPONSE_OFFSET_DLEN = 4;
268
+ declare const RESPONSE_OFFSET_BODY = 8;
269
+ declare const HANDSHAKE_FIRST = 0;
270
+ declare const HANDSHAKE_SECOND = 0;
271
+ declare const HANDSHAKE_THIRD = 0;
272
+ declare const HANDSHAKE_FOURTH = 4;
273
+ declare const HANDSHAKE_FIFTH = 2012;
274
+ declare const kXR_secreqs = 1;
275
+ declare const kXR_ableTLS = 2;
276
+ declare const kXR_wantTLS = 4;
277
+ declare const kXR_bifreqs = 8;
278
+ declare const kXR_ExpLogin = 1;
279
+ declare const kXR_ExpBind = 2;
280
+ declare const DEFAULT_PORT = 1094;
281
+ declare const S_IFDIR = 16384;
282
+ declare const S_IFLNK = 40960;
283
+ declare const DirlistOptions: {
284
+ readonly Online: 1;
285
+ readonly Dstat: 2;
286
+ readonly Dcksm: 4;
287
+ readonly Dstatx: 8;
231
288
  };
232
- type MkDirFlags = typeof MkDirFlags[keyof typeof MkDirFlags];
289
+ type DirlistOptions = typeof DirlistOptions[keyof typeof DirlistOptions];
290
+ declare const CRED_TYPE: Record<string, number>;
233
291
  //#endregion
234
- //#region lib/file.d.ts
235
- type Combined = number & {};
292
+ //#region src/api/types.d.ts
293
+ declare const StatFlags: {
294
+ readonly XBitSet: 1;
295
+ readonly IsDir: 2;
296
+ readonly Other: 4;
297
+ readonly Offline: 8;
298
+ readonly Readable: 16;
299
+ readonly Writable: 32;
300
+ readonly POSCPending: 64;
301
+ readonly BackUpExists: 128;
302
+ readonly CacheResp: 512;
303
+ };
304
+ type StatFlags = typeof StatFlags[keyof typeof StatFlags];
305
+ interface OpenOptions {
306
+ flags?: OpenFlags;
307
+ mode?: number;
308
+ signal?: AbortSignal;
309
+ }
310
+ interface StatInfo {
311
+ id: string;
312
+ size: bigint;
313
+ flags: number;
314
+ mtime: number;
315
+ ctime: number;
316
+ atime: number;
317
+ mode: number;
318
+ owner: string;
319
+ group: string;
320
+ get isDirectory(): boolean;
321
+ get isLink(): boolean;
322
+ get isOffline(): boolean;
323
+ get isCached(): boolean;
324
+ }
236
325
  /**
237
- * XRootD File 客户端
238
- * 提供对远程文件的异步读写操作及 Node.js 风格的流式接口。
326
+ * Parse XRootD stat response string.
327
+ *
328
+ * Format: "<id> <size> <flags> <mtime> <ctime> <atime> <mode> <owner> <group>"
329
+ * - id: opaque 64-bit device id (string to avoid precision loss)
330
+ * - size: uint64 file size (bigint)
331
+ * - flags: XRootD flags bitmask (StatFlags)
332
+ * - mtime: modification time (epoch seconds)
333
+ * - ctime: change time (epoch seconds)
334
+ * - atime: access time (epoch seconds)
335
+ * - mode: POSIX mode (octal string, e.g. "100644")
336
+ * - owner: file owner
337
+ * - group: file group
239
338
  */
240
- declare class File$1 {
241
- private _internal;
242
- constructor(internalInstance?: INativeFile);
243
- /**
244
- * 打开远程文件
245
- * @param url 目标地址 (如 root://server//path/to/file)
246
- * @param flags 打开标志位
247
- * @param mode 访问权限模式
248
- */
249
- open(url: string, flags?: OpenFlags | Combined, mode?: AccessMode | Combined): Promise<void>;
250
- /**
251
- * 关闭文件
252
- */
339
+ declare function createStatInfo(data: string): StatInfo;
340
+ interface ChunkInfo {
341
+ fhandle: Uint8Array;
342
+ offset: number;
343
+ length: number;
344
+ data?: Uint8Array;
345
+ }
346
+ interface Location {
347
+ host: string;
348
+ port: number;
349
+ }
350
+ interface LocationInfo {
351
+ locations: Location[];
352
+ get isServer(): boolean;
353
+ get isManager(): boolean;
354
+ get isRedirect(): boolean;
355
+ }
356
+ interface DirectoryList {
357
+ name: string;
358
+ entries: DirectoryEntry[];
359
+ }
360
+ interface ProtocolInfo {
361
+ version: number;
362
+ flags: number;
363
+ }
364
+ interface AuthConfig {
365
+ username?: string;
366
+ password?: string;
367
+ protocol?: string;
368
+ }
369
+ interface DirectoryEntry {
370
+ name: string;
371
+ size: number;
372
+ flags: number;
373
+ mtime: number;
374
+ }
375
+ //#endregion
376
+ //#region src/api/file.d.ts
377
+ declare class File {
378
+ private mux;
379
+ private session;
380
+ private fhandle;
381
+ private _isOpen;
382
+ constructor(mux: Multiplexer, session: Session);
383
+ get isOpen(): boolean;
384
+ open(path: string, options?: {
385
+ flags?: number;
386
+ mode?: number;
387
+ }): Promise<void>;
388
+ read(offset: number, size: number): Promise<Uint8Array>;
389
+ write(offset: number, data: Uint8Array): Promise<number>;
253
390
  close(): Promise<void>;
254
- /**
255
- * 获取文件状态
256
- */
257
391
  stat(): Promise<StatInfo>;
258
- /**
259
- * 读取文件块 (Zero-Copy from C++)
260
- * @param offset 偏移量 (支持 >2GB)
261
- * @param size 读取字节数
262
- * @returns 包含数据的 Node.js Buffer
263
- */
264
- read(offset: bigint | number, size: number): Promise<Buffer>;
265
- /**
266
- * 写入文件块 (Buffer 写入)
267
- * @param offset 偏移量
268
- * @param buffer 要写入的数据
269
- */
270
- write(offset: bigint | number, buffer: Buffer): Promise<void>;
271
- /**
272
- * 从本地 fd 写入文件块
273
- * @param offset 写入的起始字节偏移量。
274
- * @param size 写入大小。
275
- * @param fd 本地文件描述符 (fd)。
276
- * @param fdoff 可选,从本地 fd 中读取的起始偏移。
277
- */
278
- write(offset: bigint | number, size: number, fd: number, fdoff?: bigint | number): Promise<void>;
279
- /**
280
- * 从本地 fd 写入文件块 (直接映射)
281
- * @param offset 写入的起始字节偏移量。
282
- * @param size 写入大小。
283
- * @param fd 本地文件描述符 (fd)。
284
- * @param fdoff 可选,从本地 fd 中读取的起始偏移。
285
- */
286
- writeFd(offset: bigint | number, size: number, fd: number, fdoff?: bigint | number): Promise<void>;
287
- /**
288
- * 同步文件缓冲区到磁盘
289
- */
290
392
  sync(): Promise<void>;
291
- /**
292
- * 截断文件
293
- * @param size 目标大小
294
- */
295
- truncate(size: bigint | number): Promise<void>;
296
- /**
297
- * 检查本地实例状态 (同步操作)
298
- */
299
- isOpen(): boolean;
300
- getProperty(name: string): Promise<string>;
301
- setProperty(name: string, value: string): Promise<boolean>;
302
- /**
303
- * 向量化读取 (Vector Read)
304
- * 在单个请求中从文件的多个非连续区域读取数据,极大地减少网络往返开销。
305
- * @param chunks 包含 offset 和 size 的读取请求数组
306
- * @returns 与请求数组顺序对应的 Buffer 数组
307
- */
308
- vectorRead(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
309
- /**
310
- * 读取块 (Read Chunks)
311
- * 类似于 VectorRead,但底层实现可能利用更高级的预读或多路复用策略。
312
- */
313
- readChunks(chunks: ReadChunkRequest[]): Promise<Buffer[]>;
314
- /**
315
- * 设置文件的扩展属性
316
- */
317
- setXAttrs(attrs: Record<string, string>): Promise<XAttrStatusResult[]>;
318
- /**
319
- * 设置文件的扩展属性
320
- */
321
- setXAttr(key: string, value: string): Promise<boolean>;
322
- /**
323
- * 获取文件的扩展属性
324
- */
325
- getXAttrs(keys: string[]): Promise<Record<string, string>>;
326
- getXAttr(key: string): Promise<string>;
327
- /**
328
- * 删除文件的扩展属性
329
- */
330
- delXAttrs(keys: string[]): Promise<XAttrStatusResult[]>;
331
- delXAttr(key: string): Promise<boolean>;
332
- /**
333
- * 列出文件所有的扩展属性和内容
334
- */
335
- listXAttrs(): Promise<Record<string, string>>;
336
- /**
337
- * 将其他文件的指定区间在服务器端克隆到当前文件
338
- * 当前文件必须以写入/更新模式打开
339
- */
340
- clone(locations: CloneLocationRequest[]): Promise<void>;
341
- /**
342
- * 创建一个可读流 (Readable Stream)
343
- * 使得 XRootD 文件可以无缝 pipe 到其他 Node.js 流 (如本地 fs, HTTP response)
344
- */
345
- createReadStream(options?: ReadStreamOptions): Readable;
346
- /**
347
- * 创建一个可写流 (Writable Stream)
348
- * 支持通过 pipe 将大量数据流式写入 XRootD 服务器
349
- */
350
- createWriteStream(options?: WriteStreamOptions): Writable;
393
+ truncate(size: number): Promise<void>;
351
394
  }
352
395
  //#endregion
353
- //#region lib/filesystem.d.ts
354
- /**
355
- * XRootD FileSystem 客户端
356
- * 提供对远程服务器目录和文件的通用管理操作。
357
- */
358
- declare class FileSystem {
359
- private _internal;
360
- readonly serverUrl: string;
361
- /**
362
- * 实例化一个 FileSystem 客户端
363
- * @param url 服务器地址 (例如: 'root://eospublic.cern.ch')
364
- */
365
- constructor(url: string);
366
- /**
367
- * 内部辅助方法:确保路径是标准的 Unix 绝对路径
368
- */
369
- private _normalize;
370
- /**
371
- * 定位文件在集群中的具体数据节点
372
- * @param filePath 目标文件路径
373
- * @param flags 定位标志位 (默认 0)
374
- * @returns 包含主机、端口等信息的数组
375
- */
376
- locate(filePath: string, flags?: number): Promise<LocationInfo[]>;
377
- /**
378
- * 获取文件或目录的状态信息
379
- * @param targetPath 目标路径
380
- */
381
- stat(targetPath: string): Promise<StatInfo>;
382
- /**
383
- * 删除远程文件
384
- * @param filePath 要删除的文件路径
385
- */
386
- rm(filePath: string): Promise<void>;
387
- /**
388
- * 创建远程目录
389
- * @param dirPath 目录路径
390
- * @param flags 标志位 (例如 MakePath,允许创建多级父目录)
391
- * @param mode 访问权限模式 (默认 0755 对应的 AccessMode)
392
- */
393
- mkdir(dirPath: string, flags?: MkDirFlags, mode?: AccessMode): Promise<void>;
394
- /**
395
- * 删除远程目录 (目录必须为空)
396
- * @param dirPath 要删除的目录路径
397
- */
398
- rmdir(dirPath: string): Promise<void>;
399
- /**
400
- * 移动或重命名文件/目录
401
- * @param source 源路径
402
- * @param dest 目标路径
403
- */
404
- mv(source: string, dest: string): Promise<void>;
405
- /**
406
- * 列出目录下的所有文件和子目录名
407
- * @param dirPath 目录路径
408
- * @param flags 标志位 (例如是否显示隐藏文件)
409
- */
410
- dirList(dirPath: string, flags?: number): Promise<DirListEntry[]>;
411
- /**
412
- * 检查文件或目录是否存在
413
- * (通过捕获 stat 的错误来实现,类似于老版本 Node 的 fs.exists)
414
- * @param targetPath 目标路径
415
- */
416
- exists(targetPath: string): Promise<boolean>;
417
- /**
418
- * 确保目录存在。如果目录不存在,则会自动创建它及其所有父目录。
419
- * (类似于 fs-extra 的 ensureDir 或 mkdir -p)
420
- * @param dirPath 目标目录
421
- */
422
- ensureDir(dirPath: string): Promise<void>;
423
- /**
424
- * 深度定位:返回包含所有数据节点副本的详细物理位置信息
425
- */
426
- deepLocate(filePath: string, flags?: number): Promise<LocationInfo[]>;
427
- /**
428
- * 在不打开文件的情况下,直接截断目标文件
429
- */
430
- truncate(filePath: string, size: bigint | number): Promise<void>;
431
- /**
432
- * 更改远程文件或目录的访问权限
433
- */
434
- chmod(targetPath: string, mode: AccessMode): Promise<void>;
435
- /**
436
- * 探活:检查远端文件系统服务是否响应
437
- */
438
- ping(): Promise<void>;
439
- /**
440
- * 获取虚拟文件系统(VFS)的状态(如磁盘总容量、剩余可用空间)
441
- */
442
- statVFS(targetPath: string): Promise<StatVFSInfo>;
443
- /**
444
- * 获取当前连接协议的详细属性
445
- */
446
- protocol(): Promise<PropertyList>;
447
- /**
448
- * 发送带外查询指令到数据节点 (通常用于 XRootD 的高级自定义插件)
449
- */
450
- query(queryCode: number, args: Buffer): Promise<Buffer>;
451
- /**
452
- * 发送通用信息到服务器
453
- */
454
- sendInfo(info: string): Promise<Buffer>;
455
- /**
456
- * 发送缓存操作信息给集群
457
- */
458
- sendCache(info: string): Promise<Buffer>;
459
- /**
460
- * 数据预热/暂存 (Staging):
461
- * 在处理海量物理数据时,通知存储集群将特定的冷数据(如磁带上的文件)提前拉取到磁盘缓存。
462
- * @param targetPaths 需要预热的路径数组
463
- * @param flags 预热策略标志
464
- * @param priority 优先级
465
- */
466
- prepare(targetPaths: string[], flags?: number, priority?: number): Promise<Buffer>;
467
- /**
468
- * 获取文件系统属性
469
- */
470
- getProperty(name: string): {
471
- success: boolean;
472
- value: string;
396
+ //#region src/client.d.ts
397
+ interface XRootDClientOptions {
398
+ credentials?: {
399
+ username: string;
400
+ password?: string;
473
401
  };
474
- /**
475
- * 设置文件系统属性
476
- */
477
- setProperty(name: string, value: string): boolean;
478
- /**
479
- * 设置扩展属性
480
- * @param targetPath 目标路径
481
- * @param attrs 扩展属性键值对记录
482
- */
483
- setXAttrs(targetPath: string, attrs: Record<string, string>): Promise<XAttrStatusResult[]>;
484
- setXAttr(targetPath: string, key: string, value: string): Promise<boolean>;
485
- /**
486
- * 获取扩展属性
487
- * @param targetPath 目标路径
488
- * @param keys 需要获取的属性名数组
489
- */
490
- getXAttrs(targetPath: string, keys: string[]): Promise<Record<string, string>>;
491
- getXAttr(targetPath: string, key: string): Promise<string>;
492
- /**
493
- * 删除指定的扩展属性
494
- * @param targetPath 目标路径
495
- * @param keys 需要删除的属性名数组
496
- */
497
- delXAttrs(targetPath: string, keys: string[]): Promise<XAttrStatusResult[]>;
498
- delXAttr(targetPath: string, key: string): Promise<boolean>;
499
- /**
500
- * 列出目标文件或目录的所有扩展属性
501
- */
502
- listXAttr(targetPath: string): Promise<Record<string, string>>;
402
+ timeout?: number;
403
+ maxRedirects?: number;
404
+ }
405
+ declare class XRootDClient {
406
+ private readonly url;
407
+ private readonly options;
408
+ private transport;
409
+ private mux;
410
+ private session;
411
+ private fs;
412
+ constructor(url: string, options?: XRootDClientOptions);
413
+ connect(): Promise<void>;
414
+ private doConnect;
415
+ private handleRedirect;
416
+ open(path: string, options?: {
417
+ flags?: number;
418
+ mode?: number;
419
+ }): Promise<File>;
420
+ stat(path: string): Promise<StatInfo>;
421
+ statFilesystem(path: string): Promise<StatInfo>;
422
+ readdir(path: string): Promise<DirectoryList>;
423
+ mkdir(path: string, mode?: number): Promise<void>;
424
+ rmdir(path: string): Promise<void>;
425
+ rm(path: string): Promise<void>;
426
+ mv(source: string, target: string): Promise<void>;
427
+ close(): Promise<void>;
428
+ get isConnected(): boolean;
429
+ get location(): string;
430
+ private ensureConnected;
431
+ private ensureFileSystem;
432
+ }
433
+ //#endregion
434
+ //#region src/api/filesystem.d.ts
435
+ declare class FileSystem {
436
+ private mux;
437
+ constructor(mux: Multiplexer);
438
+ stat(path: string): Promise<StatInfo>;
439
+ readdir(path: string): Promise<DirectoryList>;
440
+ mkdir(path: string, mode?: number): Promise<void>;
441
+ rmdir(path: string): Promise<void>;
442
+ rm(path: string): Promise<void>;
443
+ mv(source: string, target: string): Promise<void>;
444
+ private handleError;
445
+ }
446
+ //#endregion
447
+ //#region src/api/errors.d.ts
448
+ /** Error codes that can be used with XRootDError. */
449
+ type ErrorCode = ServerError | ClientError;
450
+ declare class XRootDError extends Error {
451
+ readonly code: ErrorCode | number;
452
+ readonly errno?: number;
453
+ constructor(code: ErrorCode | number, message?: string, errno?: number);
454
+ static codeToMessage(code: ErrorCode | number): string;
503
455
  }
504
456
  //#endregion
505
- //#region lib/copy.d.ts
506
- declare class CopyProcess {
507
- private nativeCp;
508
- constructor();
509
- /**
510
- * Add a job to the copy process synchronously
511
- */
512
- addJob(config: CopyJobConfig): void;
513
- /**
514
- * Asynchronously prepare the jobs (resolve DNS, check endpoints, etc.)
515
- */
516
- prepare(): Promise<void>;
517
- /**
518
- * Run the copy process.
519
- * @param onProgress Optional progress callback
520
- * @returns Array of results corresponding to the jobs added
521
- */
522
- run(onProgress?: ProgressCallback): Promise<CopyJobResult[]>;
523
- /**
524
- * Abort the running copy process.
525
- */
526
- abort(): void;
527
- /**
528
- * Abort the running copy process. (alias for abort)
529
- */
530
- cancelJob(): void;
457
+ //#region src/transport/transport.d.ts
458
+ declare class Transport implements ITransport {
459
+ private socket;
460
+ private closeCallback;
461
+ private errorCallback;
462
+ private dataHandlers;
463
+ private dataListenerInstalled;
464
+ connect(host: string, port: number, useTls?: boolean): Promise<void>;
465
+ send(data: Buffer): Promise<void>;
466
+ onData(callback: (chunk: Buffer) => void): void;
467
+ removeDataHandler(callback: (chunk: Buffer) => void): void;
468
+ onClose(callback: () => void): void;
469
+ onError(callback: (err: Error) => void): void;
470
+ close(): Promise<void>;
471
+ destroy(): void;
472
+ private tcpConnect;
473
+ private tlsConnect;
531
474
  }
532
475
  //#endregion
533
- //#region lib/url.d.ts
476
+ //#region src/protocol/message-class.d.ts
534
477
  /**
535
- * TypeScript 实现的 XRootD URL 解析器
536
- * 安全、轻量,避免跨越 C++ N-API 边界
478
+ * Message builder for constructing binary protocol messages.
479
+ * Tracks offset automatically during writes.
537
480
  */
538
- declare class XRootDUrl {
539
- private _url;
540
- readonly isValid: boolean;
541
- constructor(urlString: string);
542
- get protocol(): string;
543
- set protocol(protocol: string);
544
- get hostName(): string;
545
- set hostName(hostName: string);
546
- get port(): number;
547
- set port(port: number | string);
548
- get userName(): string;
549
- set userName(userName: string);
550
- get password(): string;
551
- set password(password: string);
552
- get hostId(): string;
553
- set pathWithParams(path: string);
554
- get pathWithParams(): string;
555
- set searchParams(params: string);
556
- get searchParams(): string;
557
- set anchor(anchor: string);
558
- get anchor(): string;
559
- set path(path: string);
560
- get path(): string;
561
- getParams(): Record<string, string>;
562
- toString(): string;
563
- static isValid(urlString: string): boolean;
481
+ declare class Message {
482
+ private buffer;
483
+ private offset;
484
+ constructor(size: number);
485
+ writeInt32BE(value: number): void;
486
+ writeInt16BE(value: number): void;
487
+ writeUInt8(value: number): void;
488
+ writeBytes(data: Uint8Array): void;
489
+ readInt32BE(): number;
490
+ readInt16BE(): number;
491
+ readBytes(length: number): Buffer;
492
+ getBuffer(): Buffer;
564
493
  }
565
494
  //#endregion
566
- //#region lib/env.d.ts
567
- type String = string;
568
- type Int = number | bigint;
569
- type Bool = 'true' | 'false';
495
+ //#region src/protocol/builders.d.ts
496
+ /**
497
+ * Request builders for XRootD protocol messages.
498
+ * Each function creates a Buffer ready to send on the wire.
499
+ */
500
+ /**
501
+ * Initial handshake (20 B) + kXR_protocol (24 B) merged into one 44-byte
502
+ * buffer ready to send immediately after TCP connect.
503
+ *
504
+ * Layout:
505
+ * [0..19] ClientInitHandShake
506
+ * [20..43] kXR_protocol request (streamid=0, body, dlen)
507
+ */
508
+ declare function buildHandshakeAndProtocol(streamId: number, flags?: number, expect?: number): Buffer;
509
+ /**
510
+ * kXR_login request (24 B header only, or 24 B + CGI string).
511
+ *
512
+ * Body layout (16 B):
513
+ * pid[4] + username[8] + ability2[1] + ability[1] + capver[1] + reserved[1]
514
+ */
515
+ declare function buildLoginRequest(streamId: number, pid: number, username: string, ability?: number, cgi?: string): Buffer;
516
+ /**
517
+ * kXR_open request (24 B header + path string).
518
+ *
519
+ * Body layout (16 B):
520
+ * mode[2] + options[2] + optiont[2] + reserved[6] + fhtemplt[4]
521
+ */
522
+ declare function buildOpenRequest(streamId: number, path: string, options: number, mode?: number): Buffer;
570
523
  /**
571
- * XRootD 底层客户端环境变量配置
572
- * 参考自: XrdClConstants.hh 与 XrdClDefaultEnv.cc
524
+ * kXR_read request (24 B header, no extra data).
525
+ *
526
+ * Body layout (16 B):
527
+ * fhandle[4] + offset[8] + rlen[4]
573
528
  */
574
- interface XRootDEnvConfig {
575
- /**
576
- * 每个通道的子流数量,用于多路复用并行传输。默认值: 1
577
- */
578
- SubStreamsPerChannel?: Int;
579
- /**
580
- * 默认的请求超时时间 (秒)。
581
- * 注意: XRootD C++ 默认是 1800(30 分钟),本 Node.js 库初始化时重置为 30。
582
- */
583
- RequestTimeout?: Int;
584
- /**
585
- * 连接重试次数。默认值: 5
586
- */
587
- ConnectionRetry?: Int;
588
- /**
589
- * 连接窗口时间 (秒)。如果在该窗口内没有成功建立连接,则报错。默认值: 120
590
- */
591
- ConnectionWindow?: Int;
592
- /**
593
- * 流超时时间 (秒)。默认值: 60
594
- */
595
- StreamTimeout?: Int;
596
- /**
597
- * 超时检测的时间精度/分辨率 (秒)。默认值: 15
598
- */
599
- TimeoutResolution?: Int;
600
- /**
601
- * 流错误统计的时间窗口长度 (秒)。默认值: 1800
602
- */
603
- StreamErrorWindow?: Int;
604
- /**
605
- * 是否启用多进程 fork 处理器,用于管理多线程 fork 同步。默认值: 1
606
- */
607
- RunForkHandler?: Int;
608
- /**
609
- * 重定向的最大限制次数。默认值: 16
610
- */
611
- RedirectLimit?: Int;
612
- /**
613
- * 内部工作线程数。默认值: 3。注意:本 Node.js 库初始化时重置为 4。
614
- */
615
- WorkerThreads?: Int;
616
- /**
617
- * 并发运行的事件循环数量。默认值: 10
618
- */
619
- ParallelEvtLoop?: Int;
620
- /**
621
- * 是否启用 TCP_NODELAY (禁用 Nagle 算法)。默认值: Linux 下为 1,OSX 下为 0
622
- */
623
- NoDelay?: Int;
624
- /**
625
- * 异步 I/O 通知使用的信号(0 表示不使用)。默认值: 0
626
- */
627
- AioSignal?: Int;
628
- /**
629
- * Copy 复制过程所使用的基本分块大小 (字节)。默认值: 8388608 (8MB)
630
- */
631
- CPChunkSize?: Int;
632
- /**
633
- * Copy 过程中同时并发传输的分块数量。默认值: 4
634
- */
635
- CPParallelChunks?: Int;
636
- /**
637
- * Copy 任务的初始化阶段超时时间 (秒)。默认值: 600
638
- */
639
- CPInitTimeout?: Int;
640
- /**
641
- * 第三方复制 (Third Party Copy, TPC) 过程超时时间 (秒)。默认值: 1800
642
- */
643
- CPTPCTimeout?: Int;
644
- /**
645
- * 整个 Copy 复制任务的总体超时时间 (秒,0 表示不限制)。默认值: 0
646
- */
647
- CPTimeout?: Int;
648
- /**
649
- * 扩展 Copy 的单次写入最大块大小 (字节)。默认值: 134217728 (128MB)
650
- */
651
- XCpBlockSize?: Int;
652
- /**
653
- * 写入被引导至负载均衡器时的重试次数上限。默认值: 3
654
- */
655
- RetryWrtAtLBLimit?: Int;
656
- /**
657
- * Copy 任务的重试次数。默认值: 0
658
- */
659
- CpRetry?: Int;
660
- /**
661
- * 在 Copy 复制传输时,是否启用渐进式读写。默认值: 1
662
- */
663
- CpUsePgWrtRd?: Int;
664
- /**
665
- * 复制文件时是否保留扩展属性 (XAttrs)。默认值: 0
666
- */
667
- PreserveXAttrs?: Int;
668
- /**
669
- * Copy 任务失败后的重试策略。默认值: "force"
670
- */
671
- CpRetryPolicy?: 'force' | 'continue';
672
- /**
673
- * Copy 操作的目标类型。默认值: ""
674
- */
675
- CpTarget?: String;
676
- /**
677
- * 是否启用 TCP Keep-Alive。默认值: 0
678
- */
679
- TCPKeepAlive?: Int;
680
- /**
681
- * TCP 空闲多长时间后发送首次 Keep-Alive 探测包 (秒)。默认值: 7200
682
- */
683
- TCPKeepAliveTime?: Int;
684
- /**
685
- * 两次 TCP Keep-Alive 探测包 of 发送间隔时间 (秒)。默认值: 75
686
- */
687
- TCPKeepAliveInterval?: Int;
688
- /**
689
- * 连接断开前,最大允许的 TCP Keep-Alive 探测未响应次数。默认值: 9
690
- */
691
- TCPKeepAliveProbes?: Int;
692
- /**
693
- * 数据服务器连接的生存时间 (TTL,秒)。默认值: 300
694
- */
695
- DataServerTTL?: Int;
696
- /**
697
- * 负载均衡器连接的生存时间 (TTL,秒)。默认值: 1200
698
- */
699
- LoadBalancerTTL?: Int;
700
- /**
701
- * 解析 IP 后是否禁止打乱顺序 (打乱顺序有利于负载均衡)。默认值: 0
702
- */
703
- IPNoShuffle?: Int;
704
- /**
705
- * 定位端点时是否记录并排除已尝试失败的地址。默认值: 1
706
- */
707
- PreserveLocateTried?: Int;
708
- /**
709
- * DNS 解析时是否优先选择 IPv4 而非 IPv6。默认值: 0
710
- */
711
- PreferIPv4?: Int;
712
- /**
713
- * 首选的 Poller 轮询器实现。默认值: "built-in"
714
- */
715
- PollerPreference?: 'built-in' | (string & {});
716
- /**
717
- * 使用的网络协议栈 (如 "IPAuto", "IPv4", "IPv6")。默认值: "IPAuto"
718
- */
719
- NetworkStack?: 'IPAuto' | 'IPv4' | 'IPv6' | 'IPv4Mapped6' | 'IPAll';
720
- /**
721
- * 读数据失败时的恢复策略。默认值: "true"
722
- */
723
- ReadRecovery?: Bool;
724
- /**
725
- * 写数据失败时的恢复策略。默认值: "true"
726
- */
727
- WriteRecovery?: Bool;
728
- /**
729
- * 打开文件失败时的恢复策略。默认值: "true"
730
- */
731
- OpenRecovery?: Bool;
732
- /**
733
- * 是否启用 Metalink 解析和处理。默认值: 1
734
- */
735
- MetalinkProcessing?: Int;
736
- /**
737
- * 是否允许解析本地存储 of Metalink 文件。默认值: 0
738
- */
739
- LocalMetalinkFile?: Int;
740
- /**
741
- * 等待 Metalink 下载的最大时间 (秒)。默认值: 60
742
- */
743
- MaxMetalinkWait?: Int;
744
- /**
745
- * 是否对 Zip 文件的 Metalink 执行校验和检查。默认值: 0
746
- */
747
- ZipMtlnCksum?: Int;
748
- /**
749
- * 强制使用的安全协议,例如 "unix" 或 "krb5,unix"(底层通过系统环境变量设置)。
750
- */
751
- SecProtocol?: 'unix' | 'sss' | 'krb5' | 'pwd' | 'gsi' | 'host' | 'ztn' | (string & {});
752
- /**
753
- * 未授权 (Permission Denied) 时,触发自动刷新证书并重试的次数上限。默认值: 3
754
- */
755
- NotAuthorizedRetryLimit?: Int;
756
- /**
757
- * 如果 TLS 握手失败,是否允许降级为非 TLS 明文传输。默认值: 0
758
- */
759
- NoTlsOK?: Int;
760
- /**
761
- * 是否只对控制通道加密(控制通道加密,数据通道明文)。默认值: 0
762
- */
763
- TlsNoData?: Int;
764
- /**
765
- * 获取 Metalink 配置文件时是否启用 TLS。默认值: 0
766
- */
767
- TlsMetalink?: Int;
768
- /**
769
- * 是否在访问非渐进式文件时要求 TLS。默认值: 0
770
- */
771
- WantTlsOnNoPgrw?: Int;
772
- /**
773
- * TLS 调试级别(如 "OFF", "INFO", "DEBUG")。默认值: "OFF"
774
- */
775
- TlsDbgLvl?: 'OFF' | 'CTX' | 'SOK' | 'SIO' | 'ALL' | 'OUT' | 'INFO' | 'DEBUG' | (string & {});
776
- /**
777
- * 是否启用多协议通道支持。默认值: 0
778
- */
779
- MultiProtocol?: Int;
780
- /**
781
- * 日志文件路径。底层拦截设置,直接对 C++ logger 生效。默认值: ""
782
- */
783
- LogFile?: String;
784
- /**
785
- * 调试日志级别(如 "Dump", "Debug", "Info", "Warning", "Error", "")。底层拦截设置。
786
- */
787
- DebugLevel?: 'Dump' | 'Debug' | 'Info' | 'Warning' | 'Error' | '';
788
- /**
789
- * 日志掩码,指定哪些子系统输出日志。底层拦截设置。
790
- */
791
- LogMask?: String;
792
- /**
793
- * 客户端配置文件加载目录。默认值: ""
794
- */
795
- ClConfDir?: String;
796
- /**
797
- * 默认客户端配置文件的绝对路径。默认值: ""
798
- */
799
- DefaultClConfFile?: String;
800
- /**
801
- * 安全或传输插件配置文件的加载目录。默认值: ""
802
- */
803
- PlugInConfDir?: String;
804
- /**
805
- * 指定动态加载的插件名称。默认值: ""
806
- */
807
- PlugIn?: String;
808
- /**
809
- * 外部客户端监控插件动态链接库的加载路径。默认值: ""
810
- */
811
- ClientMonitor?: String;
812
- /**
813
- * 传递给外部客户端监控插件的参数字符串。默认值: ""
814
- */
815
- ClientMonitorParam?: String;
816
- /**
817
- * 应用的标识名称。默认值: 当前可执行文件名
818
- */
819
- AppName?: String;
820
- /**
821
- * 监控上报信息内容。默认值: ""
822
- */
823
- MonInfo?: String;
529
+ declare function buildReadRequest(streamId: number, fhandle: Uint8Array, offset: number, rlen: number): Buffer;
530
+ /**
531
+ * kXR_write request (24 B header + data bytes).
532
+ *
533
+ * Body layout (16 B):
534
+ * fhandle[4] + offset[8] + pathid[1] + reserved[3]
535
+ */
536
+ declare function buildWriteRequest(streamId: number, fhandle: Uint8Array, offset: number, data: Uint8Array): Buffer;
537
+ /**
538
+ * kXR_close request (24 B header, no extra data).
539
+ *
540
+ * Body layout (16 B):
541
+ * fhandle[4] + reserved[12]
542
+ */
543
+ declare function buildCloseRequest(streamId: number, fhandle: Uint8Array): Buffer;
544
+ /**
545
+ * kXR_stat request (24 B header + optional path string).
546
+ *
547
+ * Body layout (16 B):
548
+ * options[1] + reserved[7] + wants[4] + fhandle[4]
549
+ */
550
+ declare function buildStatRequest(streamId: number, path: string, fhandle?: Uint8Array): Buffer;
551
+ //#endregion
552
+ //#region src/protocol/parsers.d.ts
553
+ /** Protocol response from kXR_protocol. */
554
+ interface ProtocolResponse {
555
+ pval: number;
556
+ flags: number;
557
+ secReqs?: string;
558
+ bifReqs?: string;
824
559
  }
825
- type KeysOfValue<T, TValue> = { [K in keyof T]: T[K] extends TValue ? K : never }[keyof T];
826
- type XRootDEnvConfigIntKey = KeysOfValue<Required<XRootDEnvConfig>, Int>;
827
- type XRootDEnvConfigBoolKey = KeysOfValue<Required<XRootDEnvConfig>, Bool>;
828
- type XRootDEnvConfigStringKey = KeysOfValue<Required<XRootDEnvConfig>, String>;
829
- declare class XRootDEnvironment {
830
- constructor();
831
- /**
832
- * 设置整数配置项,返回是否设置成功。
833
- */
834
- putInt(key: XRootDEnvConfigIntKey, intVal: number | bigint): boolean;
835
- /**
836
- * 设置字符串配置项,返回是否设置成功。
837
- */
838
- putString<Key extends XRootDEnvConfigStringKey | XRootDEnvConfigBoolKey>(key: Key, strVal: XRootDEnvConfig[Key]): boolean;
839
- /**
840
- * 设置布尔配置项,返回是否设置成功。
841
- */
842
- putBoolean(key: XRootDEnvConfigBoolKey, boolVal: boolean | Bool): boolean;
843
- /**
844
- * 获取整数配置项。
845
- */
846
- getInt(key: XRootDEnvConfigIntKey): number | undefined;
847
- /**
848
- * 获取字符串配置项。
849
- */
850
- getString(key: XRootDEnvConfigStringKey): string | undefined;
851
- /**
852
- * 批量安全地设置 XRootD 底层参数
853
- */
854
- configure(config: XRootDEnvConfig): void;
855
- /**
856
- * 获取指定配置
857
- */
858
- get(key: XRootDEnvConfigBoolKey): string | undefined;
859
- get(key: XRootDEnvConfigStringKey): string | undefined;
860
- get(key: XRootDEnvConfigIntKey): number | undefined;
560
+ /** Login response from kXR_login. */
561
+ interface LoginResponse {
562
+ sessid: Uint8Array;
563
+ secToken?: Uint8Array;
564
+ needsAuth: boolean;
861
565
  }
862
- declare const Env: XRootDEnvironment;
566
+ /** Open response from kXR_open. */
567
+ interface OpenResponse {
568
+ fhandle: Uint8Array;
569
+ cpsize: number;
570
+ cptype: string;
571
+ }
572
+ /** Error response from kXR_error. */
573
+ interface ErrorResponse {
574
+ errnum: number;
575
+ errmsg: string;
576
+ }
577
+ /** Redirect response from kXR_redirect. */
578
+ interface RedirectResponse {
579
+ port: number;
580
+ host: string;
581
+ }
582
+ /** Wait response from kXR_wait / kXR_waitresp. */
583
+ interface WaitResponse {
584
+ seconds: number;
585
+ infomsg: string;
586
+ }
587
+ /**
588
+ * Parse kXR_protocol OK response body.
589
+ *
590
+ * Body layout:
591
+ * pval[4] + flags[4] + secReqs (remaining bytes, NUL-terminated) +
592
+ * bifReqs (remaining bytes, NUL-terminated)
593
+ */
594
+ declare function parseProtocolResponse(body: Buffer): ProtocolResponse;
595
+ /**
596
+ * Parse kXR_login OK response body.
597
+ *
598
+ * Body layout:
599
+ * sessid[16] + optional secToken (remaining bytes)
600
+ */
601
+ declare function parseLoginResponse(body: Buffer): LoginResponse;
602
+ /**
603
+ * Parse kXR_open OK response body.
604
+ *
605
+ * Body layout:
606
+ * fhandle[4] + cpsize[4] + cptype[4] + optional stat
607
+ */
608
+ declare function parseOpenResponse(body: Buffer): OpenResponse;
609
+ /**
610
+ * Parse kXR_error response body.
611
+ *
612
+ * Body layout:
613
+ * errnum[4] + errmsg[variable, NUL-terminated]
614
+ */
615
+ declare function parseErrorResponse(body: Buffer): ErrorResponse;
616
+ /**
617
+ * Parse kXR_redirect response body.
618
+ *
619
+ * Body layout:
620
+ * port[4] + host[variable, NUL-terminated]
621
+ */
622
+ declare function parseRedirectResponse(body: Buffer): RedirectResponse;
623
+ /**
624
+ * Parse kXR_wait / kXR_waitresp response body.
625
+ *
626
+ * Body layout:
627
+ * seconds[4] + infomsg[variable, NUL-terminated]
628
+ */
629
+ declare function parseWaitResponse(body: Buffer): WaitResponse;
630
+ //#endregion
631
+ //#region src/protocol/codec.d.ts
632
+ /**
633
+ * Big-endian encoding / decoding utilities for the XRootD protocol.
634
+ *
635
+ * Every multi-byte field in XRootD is transmitted in network byte order
636
+ * (big-endian). The helpers below keep offset tracking explicit so
637
+ * callers never forget to advance.
638
+ */
639
+ /** Write `value` as uint16 BE at `offset`, return new offset. */
640
+ declare function put16(buf: Buffer, offset: number, value: number): number;
641
+ /** Read uint16 BE at `offset`, return `[value, newOffset]`. */
642
+ declare function get16(buf: Buffer, offset: number): [number, number];
643
+ /** Write `value` as uint32 BE at `offset`, return new offset. */
644
+ declare function put32(buf: Buffer, offset: number, value: number): number;
645
+ /** Read uint32 BE at `offset`, return `[value, newOffset]`. */
646
+ declare function get32(buf: Buffer, offset: number): [number, number];
647
+ /**
648
+ * Write `str` bytes into `buf` starting at `offset`, padded with zeros
649
+ * up to `maxLen`. Returns the new offset (always `offset + maxLen`).
650
+ */
651
+ declare function putString(buf: Buffer, offset: number, str: string, maxLen: number): number;
652
+ /**
653
+ * Read a fixed-length string from `buf` at `offset` for `length` bytes.
654
+ * Trailing NUL bytes are stripped.
655
+ */
656
+ declare function getString(buf: Buffer, offset: number, length: number): [string, number];
657
+ /** Copy `data` into `buf` at `offset`, return new offset. */
658
+ declare function putBytes(buf: Buffer, offset: number, data: Uint8Array): number;
659
+ /** Slice `length` bytes from `buf` at `offset`, return `[slice, newOffset]`. */
660
+ declare function getBytes(buf: Buffer, offset: number, length: number): [Buffer, number];
863
661
  //#endregion
864
- export { AccessMode, CopyProcess, 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 };
662
+ export { type AuthConfig, BODY_SIZE, CRED_TYPE, type ChunkInfo, ClientError, DEFAULT_PORT, type DirectoryEntry, type DirectoryList, DirlistOptions, type ErrorResponse, FHANDLE_SIZE, File, FileSystem, type Frame, Framer, HANDSHAKE_FIFTH, HANDSHAKE_FIRST, HANDSHAKE_FOURTH, HANDSHAKE_SECOND, HANDSHAKE_THIRD, type ITransport, type Location, type LocationInfo, type LoginResponse, Message, Multiplexer, OpenFlags, type OpenOptions, type OpenResponse, PROTOCOL_VERSION, type ProtocolInfo, type ProtocolResponse, REQUEST_HDR_SIZE, REQUEST_OFFSET_BODY, REQUEST_OFFSET_DLEN, REQUEST_OFFSET_REQUEST_ID, REQUEST_OFFSET_STREAM_ID, RESPONSE_HDR_SIZE, RESPONSE_OFFSET_BODY, RESPONSE_OFFSET_DLEN, RESPONSE_OFFSET_STATUS, RESPONSE_OFFSET_STREAM_ID, type RedirectResponse, RequestId, ResponseStatus, SESS_ID_SIZE, S_IFDIR, S_IFLNK, ServerError, type Session, StatFlags, type StatInfo, Transport, type WaitResponse, XRootDClient, type XRootDClientOptions, XRootDError, XRootDUrl, buildCloseRequest, buildHandshakeAndProtocol, buildLoginRequest, buildOpenRequest, buildReadRequest, buildStatRequest, buildWriteRequest, createStatInfo, get16, get32, getBytes, getString, handshake, kXR_ExpBind, kXR_ExpLogin, kXR_ableTLS, kXR_bifreqs, kXR_secreqs, kXR_wantTLS, parseErrorResponse, parseLoginResponse, parseOpenResponse, parseProtocolResponse, parseRedirectResponse, parseWaitResponse, put16, put32, putBytes, putString };
663
+ //# sourceMappingURL=index.d.mts.map