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.
package/LICENSE-MIT ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Aluria
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # XRootD Typescript Support
2
+
3
+ > [!WARNING]
4
+ > **Working in process**. This package is currently under active development and not ready for production use. Stay tuned!
5
+
6
+ - now complete: FileSystem/Url/Env
7
+ - in progress: File/CopyProcess/ErrorProcess/And others
8
+
9
+ ---
10
+
11
+ minimium gcc version for linux: GLIBCXX_3.4.26 (GCC 9 or newer) <br> minimium node version: node20
12
+
13
+ ---
14
+
15
+ License
16
+
17
+ This project follows the dual license: [GNU GPLv3](LICENSE-GPLv3) and [MIT](LICENSE-MIT).
18
+
19
+ The XRootD project is GPL, so this project is also GPL. However, the API of this project is provided under MIT license, so you can use this project in your project without any restriction.
20
+
21
+
22
+
23
+ This project is not affiliated with the XRootD project. It is a third-party project that provides a Node.js interface to the XRootD library.
package/dist/index.cjs ADDED
@@ -0,0 +1,672 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let node_stream = require("node:stream");
25
+ let node_gyp_build = require("node-gyp-build");
26
+ node_gyp_build = __toESM(node_gyp_build, 1);
27
+ let node_path = require("node:path");
28
+ node_path = __toESM(node_path, 1);
29
+ let node_url = require("node:url");
30
+ //#region lib/native.ts
31
+ const nativeAddon = (0, node_gyp_build.default)(node_path.default.resolve(__dirname, ".."));
32
+ //#endregion
33
+ //#region lib/enums.ts
34
+ /**
35
+ * XrdCl::OpenFlags - 文件打开选项
36
+ * @see src/XProtocol/XProtocol.hh:XOpenRequestOption
37
+ * @see src/XrdCl/XrdClFileSystem.hh:OpenFlags::Flags
38
+ */
39
+ const OpenFlags = {
40
+ None: 0,
41
+ Compress: 1,
42
+ Delete: 2,
43
+ Force: 4,
44
+ New: 8,
45
+ Read: 16,
46
+ Update: 32,
47
+ Refresh: 128,
48
+ MakePath: 256,
49
+ IntentDirList: 1024,
50
+ Replica: 2048,
51
+ POSC: 4096,
52
+ NoWait: 8192,
53
+ SeqIO: 16384,
54
+ Write: 32768,
55
+ PrefName: 256,
56
+ Dup: 65536,
57
+ Samefs: 131072
58
+ };
59
+ /**
60
+ * XrdCl::Access - 文件访问权限模式
61
+ * @see src/XProtocol/XProtocol.hh:XOpenRequestMode
62
+ * @see src/XrdCl/XrdClFileSystem.hh:Access::Mode
63
+ */
64
+ const AccessMode = {
65
+ None: 0,
66
+ UR: 256,
67
+ UW: 128,
68
+ UX: 64,
69
+ GR: 32,
70
+ GW: 16,
71
+ GX: 8,
72
+ OR: 4,
73
+ OW: 2,
74
+ OX: 1
75
+ };
76
+ /**
77
+ * XrdCl::MkDirFlags - 目录创建选项
78
+ * @see src/XrdCl/XrdClFileSystem.hh:MkDirFlags::Flags
79
+ */
80
+ const MkDirFlags = {
81
+ None: 0,
82
+ MakePath: 1
83
+ };
84
+ const StatFlags = {
85
+ XBitSet: 1,
86
+ //!< Executable/searchable bit set
87
+ IsDir: 2,
88
+ //!< This is a directory
89
+ Other: 4,
90
+ //!< Neither a file nor a directory
91
+ Offline: 8,
92
+ //!< File is not online (ie. on disk)
93
+ POSCPending: 64,
94
+ //!< File opened with POST flag, not yet successfully closed
95
+ IsReadable: 16,
96
+ //!< Read access is allowed
97
+ IsWritable: 32,
98
+ //!< Write access is allowed
99
+ BackUpExists: 128
100
+ };
101
+ //!< Back up copy exists
102
+ //#endregion
103
+ //#region lib/file.ts
104
+ /**
105
+ * XRootD File 客户端
106
+ * 提供对远程文件的异步读写操作及 Node.js 风格的流式接口。
107
+ */
108
+ var File = class {
109
+ _internal;
110
+ constructor(internalInstance) {
111
+ if (internalInstance) this._internal = internalInstance;
112
+ else {
113
+ if (!nativeAddon || !nativeAddon.File) throw new Error("Native addon not loaded properly.");
114
+ this._internal = new nativeAddon.File();
115
+ }
116
+ }
117
+ /**
118
+ * 打开远程文件
119
+ * @param url 目标地址 (如 root://server//path/to/file)
120
+ * @param flags 打开标志位
121
+ * @param mode 访问权限模式
122
+ */
123
+ async open(url, flags = OpenFlags.None, mode = AccessMode.None) {
124
+ return this._internal.Open(url, flags, mode);
125
+ }
126
+ /**
127
+ * 关闭文件
128
+ */
129
+ async close() {
130
+ return this._internal.Close();
131
+ }
132
+ /**
133
+ * 获取文件状态
134
+ */
135
+ async stat() {
136
+ return this._internal.Stat();
137
+ }
138
+ /**
139
+ * 读取文件块 (Zero-Copy from C++)
140
+ * @param offset 偏移量 (支持 >2GB)
141
+ * @param size 读取字节数
142
+ * @returns 包含数据的 Node.js Buffer
143
+ */
144
+ async read(offset, size) {
145
+ return this._internal.Read(BigInt(offset), size);
146
+ }
147
+ /**
148
+ * 写入文件块
149
+ * @param offset 偏移量
150
+ * @param buffer 要写入的数据
151
+ */
152
+ async write(offset, buffer) {
153
+ return this._internal.Write(BigInt(offset), buffer);
154
+ }
155
+ /**
156
+ * 同步文件缓冲区到磁盘
157
+ */
158
+ async sync() {
159
+ return this._internal.Sync();
160
+ }
161
+ /**
162
+ * 截断文件
163
+ * @param size 目标大小
164
+ */
165
+ async truncate(size) {
166
+ return this._internal.Truncate(BigInt(size));
167
+ }
168
+ /**
169
+ * 检查本地实例状态 (同步操作)
170
+ */
171
+ isOpen() {
172
+ return this._internal.IsOpen();
173
+ }
174
+ async getProperty(name) {
175
+ return this._internal.GetProperty(name);
176
+ }
177
+ async setProperty(name, value) {
178
+ return this._internal.SetProperty(name, value);
179
+ }
180
+ /**
181
+ * 向量化读取 (Vector Read)
182
+ * 在单个请求中从文件的多个非连续区域读取数据,极大地减少网络往返开销。
183
+ * @param chunks 包含 offset 和 size 的读取请求数组
184
+ * @returns 与请求数组顺序对应的 Buffer 数组
185
+ */
186
+ async vectorRead(chunks) {
187
+ const normalizedChunks = chunks.map((c) => ({
188
+ offset: BigInt(c.offset),
189
+ size: c.size
190
+ }));
191
+ return this._internal.VectorRead(normalizedChunks);
192
+ }
193
+ /**
194
+ * 读取块 (Read Chunks)
195
+ * 类似于 VectorRead,但底层实现可能利用更高级的预读或多路复用策略。
196
+ */
197
+ async readChunks(chunks) {
198
+ const normalizedChunks = chunks.map((c) => ({
199
+ offset: BigInt(c.offset),
200
+ size: c.size
201
+ }));
202
+ return this._internal.ReadChunks(normalizedChunks);
203
+ }
204
+ /**
205
+ * 设置文件的扩展属性
206
+ */
207
+ async setXAttr(name, value) {
208
+ return this._internal.SetXAttr(name);
209
+ }
210
+ /**
211
+ * 获取文件的扩展属性
212
+ */
213
+ async getXAttr(name) {
214
+ return this._internal.GetXAttr(name);
215
+ }
216
+ /**
217
+ * 删除文件的扩展属性
218
+ */
219
+ async delXAttr(name) {
220
+ return this._internal.DelXAttr(name);
221
+ }
222
+ /**
223
+ * 列出文件所有的扩展属性名称
224
+ */
225
+ async listXAttr() {
226
+ return this._internal.ListXAttr();
227
+ }
228
+ /**
229
+ * 将其他文件的指定区间在服务器端克隆到当前文件
230
+ * 当前文件必须以写入/更新模式打开
231
+ */
232
+ clone(locations) {
233
+ return this._internal.Clone(locations);
234
+ }
235
+ /**
236
+ * 创建一个可读流 (Readable Stream)
237
+ * 使得 XRootD 文件可以无缝 pipe 到其他 Node.js 流 (如本地 fs, HTTP response)
238
+ */
239
+ createReadStream(options = {}) {
240
+ let currentOffset = options.start ?? 0n;
241
+ const endOffset = options.end;
242
+ const chunkSize = options.highWaterMark ?? 64 * 1024;
243
+ const self = this;
244
+ return new node_stream.Readable({
245
+ highWaterMark: chunkSize,
246
+ async read(size) {
247
+ try {
248
+ let bytesToRead = size;
249
+ if (endOffset !== void 0) {
250
+ const remaining = endOffset - currentOffset + 1n;
251
+ if (remaining <= 0n) {
252
+ this.push(null);
253
+ return;
254
+ }
255
+ if (remaining < BigInt(bytesToRead)) bytesToRead = Number(remaining);
256
+ }
257
+ const buffer = await self.read(currentOffset, bytesToRead);
258
+ if (buffer.length === 0) this.push(null);
259
+ else {
260
+ currentOffset += BigInt(buffer.length);
261
+ this.push(buffer);
262
+ }
263
+ } catch (err) {
264
+ this.destroy(err instanceof Error ? err : new Error(String(err)));
265
+ }
266
+ }
267
+ });
268
+ }
269
+ /**
270
+ * 创建一个可写流 (Writable Stream)
271
+ * 支持通过 pipe 将大量数据流式写入 XRootD 服务器
272
+ */
273
+ createWriteStream(options = {}) {
274
+ let currentOffset = options.start ?? 0n;
275
+ const self = this;
276
+ return new node_stream.Writable({
277
+ async write(chunk, encoding, callback) {
278
+ try {
279
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding);
280
+ await self.write(currentOffset, buffer);
281
+ currentOffset += BigInt(buffer.length);
282
+ callback();
283
+ } catch (err) {
284
+ callback(err instanceof Error ? err : new Error(String(err)));
285
+ }
286
+ },
287
+ async writev(chunks, callback) {
288
+ try {
289
+ const buffers = chunks.map((c) => Buffer.isBuffer(c.chunk) ? c.chunk : Buffer.from(c.chunk, c.encoding));
290
+ const masterBuffer = Buffer.concat(buffers);
291
+ await self.write(currentOffset, masterBuffer);
292
+ currentOffset += BigInt(masterBuffer.length);
293
+ callback();
294
+ } catch (err) {
295
+ callback(err instanceof Error ? err : new Error(String(err)));
296
+ }
297
+ }
298
+ });
299
+ }
300
+ };
301
+ //#endregion
302
+ //#region lib/utils.ts
303
+ function reverseStr(str) {
304
+ let reversed = "";
305
+ for (let i = str.length - 1; i >= 0; i--) reversed += str.charAt(i);
306
+ return reversed;
307
+ }
308
+ function isXrdError(e) {
309
+ return e instanceof Error && "xrdStatus" in e && typeof e.xrdStatus === "number" && e.xrdStatus > 0;
310
+ }
311
+ //#endregion
312
+ //#region lib/filesystem.ts
313
+ /**
314
+ * XRootD FileSystem 客户端
315
+ * 提供对远程服务器目录和文件的通用管理操作。
316
+ */
317
+ var FileSystem = class {
318
+ _internal;
319
+ serverUrl;
320
+ /**
321
+ * 实例化一个 FileSystem 客户端
322
+ * @param url 服务器地址 (例如: 'root://eospublic.cern.ch')
323
+ */
324
+ constructor(url) {
325
+ if (!nativeAddon || !nativeAddon.FileSystem) throw new Error("Native addon not loaded properly. Cannot instantiate FileSystem.");
326
+ this.serverUrl = url;
327
+ this._internal = new nativeAddon.FileSystem(url);
328
+ }
329
+ /**
330
+ * 内部辅助方法:确保路径是标准的 Unix 绝对路径
331
+ */
332
+ _normalize(targetPath) {
333
+ const posixPath = node_path.posix.normalize(targetPath);
334
+ return posixPath.startsWith("/") ? posixPath : "/" + posixPath;
335
+ }
336
+ /**
337
+ * 定位文件在集群中的具体数据节点
338
+ * @param filePath 目标文件路径
339
+ * @param flags 定位标志位 (默认 0)
340
+ * @returns 包含主机、端口等信息的数组
341
+ */
342
+ async locate(filePath, flags = 0) {
343
+ return this._internal.Locate(this._normalize(filePath), flags);
344
+ }
345
+ /**
346
+ * 获取文件或目录的状态信息
347
+ * @param targetPath 目标路径
348
+ */
349
+ async stat(targetPath) {
350
+ const rawStat = await this._internal.Stat(this._normalize(targetPath));
351
+ return {
352
+ ...rawStat,
353
+ get modeOctal() {
354
+ return reverseStr(rawStat.modeAsOctString);
355
+ },
356
+ get modeString() {
357
+ return reverseStr(rawStat.modeAsString);
358
+ },
359
+ get isFile() {
360
+ return (rawStat.flags & StatFlags.IsDir) === 0 && (rawStat.flags & StatFlags.Other) === 0;
361
+ },
362
+ get isDir() {
363
+ return (rawStat.flags & StatFlags.IsDir) !== 0;
364
+ },
365
+ get isOther() {
366
+ return (rawStat.flags & StatFlags.Other) !== 0;
367
+ },
368
+ get isOffline() {
369
+ return (rawStat.flags & StatFlags.Offline) !== 0;
370
+ },
371
+ get isPOSCPending() {
372
+ return (rawStat.flags & StatFlags.POSCPending) !== 0;
373
+ },
374
+ get isReadable() {
375
+ return (rawStat.flags & StatFlags.IsReadable) !== 0;
376
+ },
377
+ get isWritable() {
378
+ return (rawStat.flags & StatFlags.IsWritable) !== 0;
379
+ },
380
+ get isBackUpExists() {
381
+ return (rawStat.flags & StatFlags.BackUpExists) !== 0;
382
+ }
383
+ };
384
+ }
385
+ /**
386
+ * 删除远程文件
387
+ * @param filePath 要删除的文件路径
388
+ */
389
+ async rm(filePath) {
390
+ return this._internal.Rm(this._normalize(filePath));
391
+ }
392
+ /**
393
+ * 创建远程目录
394
+ * @param dirPath 目录路径
395
+ * @param flags 标志位 (例如 MakePath,允许创建多级父目录)
396
+ * @param mode 访问权限模式 (默认 0755 对应的 AccessMode)
397
+ */
398
+ async mkdir(dirPath, flags = MkDirFlags.None, mode = AccessMode.UR | AccessMode.UW | AccessMode.UX | AccessMode.GR | AccessMode.GX | AccessMode.OR | AccessMode.OX) {
399
+ return this._internal.MkDir(this._normalize(dirPath), flags, mode);
400
+ }
401
+ /**
402
+ * 删除远程目录 (目录必须为空)
403
+ * @param dirPath 要删除的目录路径
404
+ */
405
+ async rmdir(dirPath) {
406
+ return this._internal.RmDir(this._normalize(dirPath));
407
+ }
408
+ /**
409
+ * 移动或重命名文件/目录
410
+ * @param source 源路径
411
+ * @param dest 目标路径
412
+ */
413
+ async mv(source, dest) {
414
+ return this._internal.Mv(this._normalize(source), this._normalize(dest));
415
+ }
416
+ /**
417
+ * 列出目录下的所有文件和子目录名
418
+ * @param dirPath 目录路径
419
+ * @param flags 标志位 (例如是否显示隐藏文件)
420
+ */
421
+ async dirList(dirPath, flags = 0) {
422
+ return this._internal.DirList(this._normalize(dirPath), flags);
423
+ }
424
+ /**
425
+ * 检查文件或目录是否存在
426
+ * (通过捕获 stat 的错误来实现,类似于老版本 Node 的 fs.exists)
427
+ * @param targetPath 目标路径
428
+ */
429
+ async exists(targetPath) {
430
+ try {
431
+ await this.stat(targetPath);
432
+ return true;
433
+ } catch (err) {
434
+ debugger;
435
+ if (isXrdError(err)) {
436
+ if (err.xrdErrNo === 3011) return false;
437
+ }
438
+ throw err;
439
+ }
440
+ }
441
+ /**
442
+ * 确保目录存在。如果目录不存在,则会自动创建它及其所有父目录。
443
+ * (类似于 fs-extra 的 ensureDir 或 mkdir -p)
444
+ * @param dirPath 目标目录
445
+ */
446
+ async ensureDir(dirPath) {
447
+ if (!await this.exists(dirPath)) await this.mkdir(dirPath, MkDirFlags.MakePath);
448
+ }
449
+ /**
450
+ * 深度定位:返回包含所有数据节点副本的详细物理位置信息
451
+ */
452
+ async deepLocate(filePath, flags = 0) {
453
+ return this._internal.DeepLocate(this._normalize(filePath), flags);
454
+ }
455
+ /**
456
+ * 在不打开文件的情况下,直接截断目标文件
457
+ */
458
+ async truncate(filePath, size) {
459
+ return this._internal.Truncate(this._normalize(filePath), size);
460
+ }
461
+ /**
462
+ * 更改远程文件或目录的访问权限
463
+ */
464
+ async chmod(targetPath, mode) {
465
+ return this._internal.ChMod(this._normalize(targetPath), mode);
466
+ }
467
+ /**
468
+ * 探活:检查远端文件系统服务是否响应
469
+ */
470
+ async ping() {
471
+ return this._internal.Ping();
472
+ }
473
+ /**
474
+ * 获取虚拟文件系统(VFS)的状态(如磁盘总容量、剩余可用空间)
475
+ */
476
+ async statVFS(targetPath) {
477
+ return this._internal.StatVFS(this._normalize(targetPath));
478
+ }
479
+ /**
480
+ * 获取当前连接协议的详细属性
481
+ */
482
+ async protocol() {
483
+ return this._internal.Protocol();
484
+ }
485
+ /**
486
+ * 发送带外查询指令到数据节点 (通常用于 XRootD 的高级自定义插件)
487
+ */
488
+ async query(queryCode, args) {
489
+ return this._internal.Query(queryCode, args);
490
+ }
491
+ /**
492
+ * 发送通用信息到服务器
493
+ */
494
+ async sendInfo(info) {
495
+ return this._internal.SendInfo(info);
496
+ }
497
+ /**
498
+ * 发送缓存操作信息给集群
499
+ */
500
+ async sendCache(info) {
501
+ return this._internal.SendCache(info);
502
+ }
503
+ /**
504
+ * 数据预热/暂存 (Staging):
505
+ * 在处理海量物理数据时,通知存储集群将特定的冷数据(如磁带上的文件)提前拉取到磁盘缓存。
506
+ * @param targetPaths 需要预热的路径数组
507
+ * @param flags 预热策略标志
508
+ * @param priority 优先级
509
+ */
510
+ async prepare(targetPaths, flags = 0, priority = 0) {
511
+ const normalizedPaths = targetPaths.map((p) => this._normalize(p));
512
+ return this._internal.Prepare(normalizedPaths, flags, priority);
513
+ }
514
+ /**
515
+ * 获取文件系统属性
516
+ */
517
+ getProperty(name) {
518
+ return this._internal.GetProperty(name);
519
+ }
520
+ /**
521
+ * 设置文件系统属性
522
+ */
523
+ setProperty(name, value) {
524
+ return this._internal.SetProperty(name, value);
525
+ }
526
+ /**
527
+ * 设置扩展属性
528
+ * @param targetPath 目标路径
529
+ * @param attrs 扩展属性键值对记录
530
+ */
531
+ async setXAttr(targetPath, attrs) {
532
+ return this._internal.SetXAttr(this._normalize(targetPath), attrs);
533
+ }
534
+ /**
535
+ * 获取扩展属性
536
+ * @param targetPath 目标路径
537
+ * @param keys 需要获取的属性名数组
538
+ */
539
+ async getXAttr(targetPath, keys) {
540
+ return this._internal.GetXAttr(this._normalize(targetPath), keys);
541
+ }
542
+ /**
543
+ * 删除指定的扩展属性
544
+ * @param targetPath 目标路径
545
+ * @param keys 需要删除的属性名数组
546
+ */
547
+ async delXAttr(targetPath, keys) {
548
+ return this._internal.DelXAttr(this._normalize(targetPath), keys);
549
+ }
550
+ /**
551
+ * 列出目标文件或目录的所有扩展属性
552
+ */
553
+ async listXAttr(targetPath) {
554
+ return this._internal.ListXAttr(this._normalize(targetPath));
555
+ }
556
+ };
557
+ //#endregion
558
+ //#region lib/url.ts
559
+ /**
560
+ * 纯 TypeScript 实现的 XRootD URL 解析器
561
+ * 安全、轻量,避免跨越 C++ N-API 边界
562
+ */
563
+ var XRootDUrl = class XRootDUrl {
564
+ _url;
565
+ isValid;
566
+ constructor(urlString) {
567
+ this._url = new node_url.URL(urlString);
568
+ this.isValid = true;
569
+ if (![
570
+ "root",
571
+ "xrootd",
572
+ "xroot",
573
+ "file"
574
+ ].includes(this.protocol)) {
575
+ console.error("Invalid XRootD URL protocol.");
576
+ this.isValid = false;
577
+ } else if (this.hostName.length === 0) this.isValid = false;
578
+ }
579
+ get protocol() {
580
+ return this._url.protocol.replace(/:$/, "");
581
+ }
582
+ set protocol(protocol) {
583
+ this._url.protocol = protocol;
584
+ }
585
+ get hostName() {
586
+ return this._url.hostname;
587
+ }
588
+ set hostName(hostName) {
589
+ this._url.hostname = hostName;
590
+ }
591
+ get port() {
592
+ return this._url.port ? parseInt(this._url.port, 10) : 1094;
593
+ }
594
+ set port(port) {
595
+ this._url.port = port.toString();
596
+ }
597
+ get userName() {
598
+ return this._url.username;
599
+ }
600
+ set userName(userName) {
601
+ this._url.username = userName;
602
+ }
603
+ get password() {
604
+ return this._url.password;
605
+ }
606
+ set password(password) {
607
+ this._url.password = password;
608
+ }
609
+ get hostId() {
610
+ const u = this._url.username;
611
+ if (u.length === 0) return this._url.host;
612
+ else if (this._url.password.length > 0) return `${u}:${this._url.password}@${this._url.host}`;
613
+ else return `${u}@${this._url.host}`;
614
+ }
615
+ set pathWithParams(path) {
616
+ const [p, s] = path.split("?", 2);
617
+ this._url.pathname = "/" + p;
618
+ this._url.search = s ?? "";
619
+ }
620
+ get pathWithParams() {
621
+ return this.path + this._url.search;
622
+ }
623
+ set searchParams(params) {
624
+ this._url.search = params;
625
+ }
626
+ get searchParams() {
627
+ return this._url.search;
628
+ }
629
+ set anchor(anchor) {
630
+ this._url.hash = anchor;
631
+ }
632
+ get anchor() {
633
+ return this._url.hash;
634
+ }
635
+ set path(path) {
636
+ this._url.pathname = "/" + path;
637
+ }
638
+ get path() {
639
+ return this._url.pathname.replace(/^\/+/, "/");
640
+ }
641
+ getParams() {
642
+ const params = {};
643
+ for (const [key, value] of this._url.searchParams.entries()) params[key] = value;
644
+ return params;
645
+ }
646
+ toString() {
647
+ return this._url.toString();
648
+ }
649
+ static isValid(urlString) {
650
+ try {
651
+ return new XRootDUrl(urlString).isValid;
652
+ } catch {
653
+ return false;
654
+ }
655
+ }
656
+ };
657
+ //#endregion
658
+ //#region lib/env.ts
659
+ const Env = {
660
+ putInt: nativeAddon.Env.PutInt,
661
+ putString: nativeAddon.Env.PutString,
662
+ getInt: nativeAddon.Env.GetInt,
663
+ getString: nativeAddon.Env.GetString
664
+ };
665
+ //#endregion
666
+ exports.AccessMode = AccessMode;
667
+ exports.Env = Env;
668
+ exports.File = File;
669
+ exports.FileSystem = FileSystem;
670
+ exports.MkDirFlags = MkDirFlags;
671
+ exports.OpenFlags = OpenFlags;
672
+ exports.URL = XRootDUrl;