cspell-io 9.2.0 → 9.2.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.
package/dist/index.d.ts CHANGED
@@ -79,15 +79,6 @@ declare class CFileReference implements FileReference {
79
79
  static from(url: URL, encoding?: BufferEncoding, baseFilename?: string | undefined, gz?: boolean | undefined): CFileReference;
80
80
  toJson(): CFileReferenceJson;
81
81
  }
82
- /**
83
- *
84
- * @param file - a URL, file path, or FileReference
85
- * @param encoding - optional encoding used to decode the file.
86
- * @param baseFilename - optional base filename used with data URLs.
87
- * @param gz - optional flag to indicate if the file is gzipped.
88
- * @returns a FileReference
89
- */
90
-
91
82
  declare function renameFileReference(ref: FileReference, newUrl: URL): FileReference;
92
83
  //#endregion
93
84
  //#region src/common/CFileResource.d.ts
package/dist/index.js CHANGED
@@ -151,8 +151,7 @@ function swap16(data) {
151
151
  return swap16Poly(data);
152
152
  }
153
153
  function swapBytes(data) {
154
- const buf = copyArrayBufferView(data);
155
- return swap16(buf);
154
+ return swap16(copyArrayBufferView(data));
156
155
  }
157
156
 
158
157
  //#endregion
@@ -196,8 +195,7 @@ function decode(data, encoding) {
196
195
  case "base64url":
197
196
  case "hex": return arrayBufferViewToBuffer(data).toString(encoding);
198
197
  }
199
- const result = decodeToString(data, encoding);
200
- return result;
198
+ return decodeToString(data, encoding);
201
199
  }
202
200
  function encodeString(str, encoding, bom) {
203
201
  switch (encoding) {
@@ -226,8 +224,7 @@ function encodeUtf16BE(str, bom = true) {
226
224
  }
227
225
  function createTextDecoderUtf16BE() {
228
226
  try {
229
- const decoder = new TextDecoder("utf-16be");
230
- return decoder;
227
+ return new TextDecoder("utf-16be");
231
228
  } catch {
232
229
  return {
233
230
  encoding: "utf-16be",
@@ -249,8 +246,7 @@ function isGZipped(data) {
249
246
  }
250
247
  function decompressBuffer(data) {
251
248
  if (!isGZipped(data)) return data;
252
- const buf = arrayBufferViewToBuffer(data);
253
- return gunzipSync(buf);
249
+ return gunzipSync(arrayBufferViewToBuffer(data));
254
250
  }
255
251
 
256
252
  //#endregion
@@ -401,9 +397,7 @@ let FileType = /* @__PURE__ */ function(FileType$1) {
401
397
  */
402
398
  function encodeDataUrl(data, mediaType, attributes) {
403
399
  if (typeof data === "string") return encodeString$1(data, mediaType, attributes);
404
- const attribs = encodeAttributes(attributes || []);
405
- const buf = arrayBufferViewToBuffer(data);
406
- return `data:${mediaType}${attribs};base64,${buf.toString("base64url")}`;
400
+ return `data:${mediaType}${encodeAttributes(attributes || [])};base64,${arrayBufferViewToBuffer(data).toString("base64url")}`;
407
401
  }
408
402
  function toDataUrl(data, mediaType, attributes) {
409
403
  return new URL(encodeDataUrl(data, mediaType, attributes));
@@ -434,11 +428,9 @@ function decodeDataUrl(url) {
434
428
  const rawAttributes = (match.groups["attributes"] || "").split(";").filter((a) => !!a).map((entry) => entry.split("=", 2)).map(([key, value]) => [key, decodeURIComponent(value)]);
435
429
  const attributes = new Map(rawAttributes);
436
430
  const encoding = attributes.get("charset");
437
- const isBase64 = !!match.groups["base64"];
438
- const data = isBase64 ? Buffer.from(encodedData, "base64url") : Buffer.from(decodeURIComponent(encodedData));
439
431
  return {
440
432
  mediaType,
441
- data,
433
+ data: !!match.groups["base64"] ? Buffer.from(encodedData, "base64url") : Buffer.from(decodeURIComponent(encodedData)),
442
434
  encoding,
443
435
  attributes
444
436
  };
@@ -463,7 +455,6 @@ function guessMimeType(filename) {
463
455
  mimeType: "application/x-yaml",
464
456
  encoding: "utf-8"
465
457
  };
466
- return void 0;
467
458
  }
468
459
 
469
460
  //#endregion
@@ -528,8 +519,7 @@ async function fetchHead(request) {
528
519
  }
529
520
  async function fetchURL(url, signal) {
530
521
  try {
531
- const request = signal ? new Request(url, { signal }) : url;
532
- const response = await _fetch(request);
522
+ const response = await _fetch(signal ? new Request(url, { signal }) : url);
533
523
  if (!response.ok) throw FetchUrlError.create(url, response.status);
534
524
  return Buffer.from(await response.arrayBuffer());
535
525
  } catch (e) {
@@ -743,11 +733,7 @@ async function compressAndChainWriteRequest(dispatcher, fileRef, content) {
743
733
  return res.value;
744
734
  }
745
735
  function registerHandlers(serviceBus) {
746
- /**
747
- * Handlers are in order of low to high level
748
- * Order is VERY important.
749
- */
750
- const handlers = [
736
+ [
751
737
  handleRequestFsReadFile,
752
738
  handleRequestFsReadFileSync,
753
739
  handleRequestFsWriteFile,
@@ -761,8 +747,7 @@ function registerHandlers(serviceBus) {
761
747
  handleRequestFsStatSync,
762
748
  handleRequestFsStat,
763
749
  handleRequestFsStatHttp
764
- ];
765
- handlers.forEach((handler) => serviceBus.addHandler(handler));
750
+ ].forEach((handler) => serviceBus.addHandler(handler));
766
751
  }
767
752
  function encodeContent(ref, content) {
768
753
  if (typeof content === "string") {
@@ -887,7 +872,6 @@ async function findUpFromUrl(name, from, options) {
887
872
  if (dir.href === root.href || stopAtHrefs.has(dir.href)) break;
888
873
  dir = new URL("..", dir);
889
874
  }
890
- return void 0;
891
875
  }
892
876
  function makePredicate(fs$1, name, entryType) {
893
877
  if (typeof name === "function") return name;
@@ -904,7 +888,6 @@ function makePredicate(fs$1, name, entryType) {
904
888
  const found = await p;
905
889
  if (found) return found;
906
890
  }
907
- return void 0;
908
891
  };
909
892
  }
910
893
 
@@ -932,11 +915,10 @@ var CVFileSystem = class {
932
915
  return this.#core.hasProvider;
933
916
  }
934
917
  findUp(name, from, options = {}) {
935
- const opts = {
918
+ return findUpFromUrl(name, from, {
936
919
  ...options,
937
920
  fs: this.#core
938
- };
939
- return findUpFromUrl(name, from, opts);
921
+ });
940
922
  }
941
923
  };
942
924
 
@@ -1252,7 +1234,6 @@ var CVirtualFS = class {
1252
1234
  return fs$2;
1253
1235
  }
1254
1236
  if (!calledNext) return next$1(url$1);
1255
- return void 0;
1256
1237
  };
1257
1238
  };
1258
1239
  let next = (_url) => void 0;
@@ -1344,16 +1325,13 @@ function writeToFile(filename, data, encoding) {
1344
1325
  return writeToFileIterable(filename, typeof data === "string" ? [data] : data, encoding);
1345
1326
  }
1346
1327
  function writeToFileIterable(filename, data, encoding) {
1347
- const stream = Stream.Readable.from(encoderTransformer(data, encoding));
1348
- const zip = /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough();
1349
- return pipeline(stream, zip, fs.createWriteStream(filename));
1328
+ return pipeline(Stream.Readable.from(encoderTransformer(data, encoding)), /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough(), fs.createWriteStream(filename));
1350
1329
  }
1351
1330
 
1352
1331
  //#endregion
1353
1332
  //#region src/file/file.ts
1354
1333
  async function readFileText(filename, encoding) {
1355
- const fr = await getDefaultCSpellIO().readFile(filename, encoding);
1356
- return fr.getText();
1334
+ return (await getDefaultCSpellIO().readFile(filename, encoding)).getText();
1357
1335
  }
1358
1336
  function readFileTextSync(filename, encoding) {
1359
1337
  return getDefaultCSpellIO().readFileSync(filename, encoding).getText();
@@ -1383,9 +1361,9 @@ var RedirectProvider = class {
1383
1361
  this.options = options;
1384
1362
  }
1385
1363
  getFileSystem(url, next) {
1386
- if (url.protocol !== this.publicRoot.protocol || url.host !== this.publicRoot.host) return void 0;
1364
+ if (url.protocol !== this.publicRoot.protocol || url.host !== this.publicRoot.host) return;
1387
1365
  const privateFs = next(this.privateRoot);
1388
- if (!privateFs) return void 0;
1366
+ if (!privateFs) return;
1389
1367
  const shadowFS = next(url);
1390
1368
  return remapFS(this.name, privateFs, shadowFS, this.publicRoot, this.privateRoot, this.options);
1391
1369
  }
@@ -1456,26 +1434,22 @@ function remapFS(name, fs$1, shadowFs, publicRoot, privateRoot, options) {
1456
1434
  dir
1457
1435
  };
1458
1436
  };
1459
- const fs2 = {
1437
+ return fsPassThrough({
1460
1438
  stat: async (url) => {
1461
1439
  const url2 = mapUrlOrReferenceToPrivate(url);
1462
- const stat = await fs$1.stat(url2);
1463
- return stat;
1440
+ return await fs$1.stat(url2);
1464
1441
  },
1465
1442
  readFile: async (url, options$1) => {
1466
1443
  const url2 = mapUrlOrReferenceToPrivate(url);
1467
- const file = await fs$1.readFile(url2, options$1);
1468
- return mapFileResourceToPublic(file);
1444
+ return mapFileResourceToPublic(await fs$1.readFile(url2, options$1));
1469
1445
  },
1470
1446
  readDirectory: async (url) => {
1471
1447
  const url2 = mapToPrivate(url);
1472
- const dir = await fs$1.readDirectory(url2);
1473
- return dir.map(mapDirEntryToPublic);
1448
+ return (await fs$1.readDirectory(url2)).map(mapDirEntryToPublic);
1474
1449
  },
1475
1450
  writeFile: async (file) => {
1476
1451
  const fileRef2 = mapFileResourceToPrivate(file);
1477
- const fileRef3 = await fs$1.writeFile(fileRef2);
1478
- return mapFileReferenceToPublic(fileRef3);
1452
+ return mapFileReferenceToPublic(await fs$1.writeFile(fileRef2));
1479
1453
  },
1480
1454
  providerInfo: {
1481
1455
  ...fs$1.providerInfo,
@@ -1483,8 +1457,7 @@ function remapFS(name, fs$1, shadowFs, publicRoot, privateRoot, options) {
1483
1457
  },
1484
1458
  capabilities: capabilities ?? fs$1.capabilities & capabilitiesMask,
1485
1459
  dispose: () => fs$1.dispose()
1486
- };
1487
- return fsPassThrough(fs2, shadowFs, publicRoot);
1460
+ }, shadowFs, publicRoot);
1488
1461
  }
1489
1462
  function fsPassThrough(fs$1, shadowFs, root) {
1490
1463
  function gfs(ur, name) {
@@ -1496,7 +1469,7 @@ function fsPassThrough(fs$1, shadowFs, root) {
1496
1469
  });
1497
1470
  return f;
1498
1471
  }
1499
- const passThroughFs = {
1472
+ return {
1500
1473
  get providerInfo() {
1501
1474
  return fs$1.providerInfo;
1502
1475
  },
@@ -1516,7 +1489,6 @@ function fsPassThrough(fs$1, shadowFs, root) {
1516
1489
  shadowFs?.dispose();
1517
1490
  }
1518
1491
  };
1519
- return passThroughFs;
1520
1492
  }
1521
1493
 
1522
1494
  //#endregion
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "provenance": true
6
6
  },
7
- "version": "9.2.0",
7
+ "version": "9.2.2",
8
8
  "description": "A library of useful I/O functions used across various cspell tools.",
9
9
  "type": "module",
10
10
  "sideEffects": false,
@@ -52,12 +52,12 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "lorem-ipsum": "^2.0.8",
55
- "typescript": "~5.8.3",
55
+ "typescript": "~5.9.3",
56
56
  "vitest-fetch-mock": "^0.4.5"
57
57
  },
58
58
  "dependencies": {
59
- "@cspell/cspell-service-bus": "9.2.0",
60
- "@cspell/url": "9.2.0"
59
+ "@cspell/cspell-service-bus": "9.2.2",
60
+ "@cspell/url": "9.2.2"
61
61
  },
62
- "gitHead": "6004e6a19e11985bc61e6578846195be07365049"
62
+ "gitHead": "594a58399cb9dad07cbb1d9cef6f2adb87560dd7"
63
63
  }