@cspell/cspell-tools 7.3.0 → 7.3.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/app.js CHANGED
@@ -5,7 +5,7 @@ import { build } from './build.js';
5
5
  import { processCompileAction } from './compile.js';
6
6
  import * as compiler from './compiler/index.js';
7
7
  import { logWithTimestamp } from './compiler/logWithTimestamp.js';
8
- import { gzip } from './gzip/index.js';
8
+ import { gzip, OSFlags } from './gzip/index.js';
9
9
  import { reportCheckChecksumFile, reportChecksumForFiles, updateChecksumForFiles } from './shasum/shasum.js';
10
10
  import { toError } from './util/errors.js';
11
11
  const npmPackageRaw = readFileSync(new URL('../package.json', import.meta.url), 'utf8');
@@ -34,7 +34,7 @@ function addCompileOptions(compileCommand) {
34
34
  export async function run(program, argv, flags) {
35
35
  async function handleGzip(files) {
36
36
  try {
37
- await gzip(files);
37
+ await gzip(files, OSFlags.Unix);
38
38
  }
39
39
  catch (error) {
40
40
  const err = toError(error);
@@ -1,17 +1,19 @@
1
+ import assert from 'assert';
1
2
  import { promises as fs } from 'fs';
2
- import { promisify } from 'util';
3
- import * as zlib from 'zlib';
4
- const gunzip = promisify(zlib.gunzip);
3
+ import { decompress } from '../../gzip/index.js';
5
4
  const isGzFile = /\.gz$/;
6
5
  export function readTextFile(filename) {
7
6
  const content = fs
8
7
  .readFile(filename)
9
- .then((buffer) => (isGzFile.test(filename) ? gunzip(buffer) : buffer))
10
- .then((buffer) => buffer.toString('utf8'));
8
+ .then(async (buffer) => (isGzFile.test(filename) ? decompress(buffer) : buffer))
9
+ .then((buffer) => (assertIsBuffer(buffer), buffer.toString('utf8')));
11
10
  return content;
12
11
  }
13
12
  export async function readTextFileLines(filename) {
14
13
  const content = await readTextFile(filename);
15
14
  return content.split('\n');
16
15
  }
16
+ function assertIsBuffer(value) {
17
+ assert(Buffer.isBuffer(value));
18
+ }
17
19
  //# sourceMappingURL=readTextFile.js.map
@@ -1,12 +1,10 @@
1
1
  import { promises as fs } from 'fs';
2
- import { promisify } from 'util';
3
- import * as zlib from 'zlib';
4
- const gzip = promisify(zlib.gzip);
2
+ import { compress } from '../gzip/index.js';
5
3
  const isGzFile = /\.gz$/;
6
4
  export async function writeTextToFile(filename, data) {
7
5
  const useGz = isGzFile.test(filename);
8
6
  const buf = Buffer.from(data, 'utf-8');
9
- const buffer = useGz ? await gzip(buf) : buf;
7
+ const buffer = useGz ? await compress(buf) : buf;
10
8
  await fs.writeFile(filename, buffer);
11
9
  }
12
10
  export function writeTextLinesToFile(filename, lines) {
@@ -1,2 +1,16 @@
1
- export declare function compressFile(file: string): Promise<string>;
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ export declare enum OSFlags {
3
+ auto = -1,
4
+ FAT = 0,
5
+ Unix = 3,
6
+ HPFS = 6,
7
+ MACOS = 7,
8
+ NTFS = 11
9
+ }
10
+ export declare function compressFile(file: string, os?: OSFlags): Promise<string>;
11
+ export declare function compress(buf: string | Uint8Array | Buffer, os?: OSFlags): Promise<Uint8Array>;
12
+ export declare function compressSync(buf: string | Uint8Array | Buffer, os?: OSFlags): Uint8Array;
13
+ export declare function decompress(buf: Uint8Array | Buffer, encoding?: undefined): Promise<Uint8Array>;
14
+ export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8'): Promise<string>;
15
+ export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8' | undefined): Promise<string | Uint8Array>;
2
16
  //# sourceMappingURL=compressFiles.d.ts.map
@@ -1,14 +1,42 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { promisify } from 'node:util';
3
- import { gzip as gz } from 'node:zlib';
3
+ import { gunzip as gunzipCB, gzip as gz, gzipSync } from 'node:zlib';
4
4
  const gzip = promisify(gz);
5
- export async function compressFile(file) {
5
+ const gunzip = promisify(gunzipCB);
6
+ export var OSFlags;
7
+ (function (OSFlags) {
8
+ OSFlags[OSFlags["auto"] = -1] = "auto";
9
+ OSFlags[OSFlags["FAT"] = 0] = "FAT";
10
+ OSFlags[OSFlags["Unix"] = 3] = "Unix";
11
+ OSFlags[OSFlags["HPFS"] = 6] = "HPFS";
12
+ OSFlags[OSFlags["MACOS"] = 7] = "MACOS";
13
+ OSFlags[OSFlags["NTFS"] = 11] = "NTFS";
14
+ })(OSFlags || (OSFlags = {}));
15
+ // https://docs.fileformat.com/compression/gz/#:~:text=A%20GZ%20file%20is%20a,compression%20formats%20on%20UNIX%20systems.
16
+ const OSSystemIDOffset = 9;
17
+ export async function compressFile(file, os) {
6
18
  if (file.endsWith('.gz'))
7
19
  return file;
8
20
  const targetFile = file + '.gz';
9
- const buf = await readFile(file);
10
- const zBuf = await gzip(buf);
21
+ const zBuf = await compress(await readFile(file), os);
11
22
  await writeFile(targetFile, zBuf);
12
23
  return targetFile;
13
24
  }
25
+ export async function compress(buf, os) {
26
+ return fixOSSystemID(await gzip(buf), os);
27
+ }
28
+ export function compressSync(buf, os) {
29
+ return fixOSSystemID(gzipSync(buf), os);
30
+ }
31
+ function fixOSSystemID(zBuf, os = OSFlags.Unix) {
32
+ const osFlag = os == OSFlags.auto ? zBuf[OSSystemIDOffset] : os;
33
+ zBuf[OSSystemIDOffset] = osFlag;
34
+ return zBuf;
35
+ }
36
+ export async function decompress(buf, encoding) {
37
+ const dBuf = gunzip(buf);
38
+ if (!encoding)
39
+ return dBuf;
40
+ return (await dBuf).toString(encoding);
41
+ }
14
42
  //# sourceMappingURL=compressFiles.js.map
@@ -1,2 +1,3 @@
1
- export declare function gzip(globs: string[]): Promise<void>;
1
+ import type { OSFlags } from './compressFiles.js';
2
+ export declare function gzip(globs: string[], os?: OSFlags): Promise<void>;
2
3
  //# sourceMappingURL=gzip.d.ts.map
package/dist/gzip/gzip.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { globP } from '../util/globP.js';
2
2
  import { compressFile } from './compressFiles.js';
3
3
  // cspell:ignore nodir
4
- export async function gzip(globs) {
4
+ export async function gzip(globs, os) {
5
5
  const files = await globP(globs, { nodir: true });
6
6
  for (const fileName of files) {
7
- await compressFile(fileName);
7
+ await compressFile(fileName, os);
8
8
  }
9
9
  }
10
10
  //# sourceMappingURL=gzip.js.map
@@ -1,3 +1,3 @@
1
- export { compressFile } from './compressFiles.js';
1
+ export { compress, compressFile, decompress, OSFlags } from './compressFiles.js';
2
2
  export { gzip } from './gzip.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export { compressFile } from './compressFiles.js';
1
+ export { compress, compressFile, decompress, OSFlags } from './compressFiles.js';
2
2
  export { gzip } from './gzip.js';
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cspell/cspell-tools",
3
- "version": "7.3.0",
3
+ "version": "7.3.2",
4
4
  "description": "Tools to assist with the development of cSpell",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -48,13 +48,13 @@
48
48
  },
49
49
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
50
50
  "dependencies": {
51
- "@cspell/cspell-pipe": "7.3.0",
51
+ "@cspell/cspell-pipe": "7.3.2",
52
52
  "commander": "^11.0.0",
53
53
  "cosmiconfig": "8.0.0",
54
- "cspell-trie-lib": "7.3.0",
54
+ "cspell-trie-lib": "7.3.2",
55
55
  "gensequence": "^5.0.2",
56
56
  "glob": "^10.3.4",
57
- "hunspell-reader": "7.3.0",
57
+ "hunspell-reader": "7.3.2",
58
58
  "yaml": "^2.3.2"
59
59
  },
60
60
  "engines": {
@@ -68,5 +68,5 @@
68
68
  "ts-json-schema-generator": "^1.3.0"
69
69
  },
70
70
  "module": "bin.mjs",
71
- "gitHead": "4a16b099b64c5b55645529a4ae79bc32aaf0fc8e"
71
+ "gitHead": "71d88d4e4d2252124a952c78d4fc03ce0a6d67e3"
72
72
  }