@cspell/cspell-tools 7.3.1 → 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.
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
1
2
|
import { promises as fs } from 'fs';
|
|
2
|
-
import {
|
|
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) ?
|
|
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 {
|
|
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
|
|
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,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
export declare enum OSFlags {
|
|
3
|
+
auto = -1,
|
|
3
4
|
FAT = 0,
|
|
4
5
|
Unix = 3,
|
|
5
6
|
HPFS = 6,
|
|
@@ -8,6 +9,7 @@ export declare enum OSFlags {
|
|
|
8
9
|
}
|
|
9
10
|
export declare function compressFile(file: string, os?: OSFlags): Promise<string>;
|
|
10
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;
|
|
11
13
|
export declare function decompress(buf: Uint8Array | Buffer, encoding?: undefined): Promise<Uint8Array>;
|
|
12
14
|
export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8'): Promise<string>;
|
|
13
15
|
export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8' | undefined): Promise<string | Uint8Array>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
-
import { gunzip as gunzipCB, 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
5
|
const gunzip = promisify(gunzipCB);
|
|
6
6
|
export var OSFlags;
|
|
7
7
|
(function (OSFlags) {
|
|
8
|
+
OSFlags[OSFlags["auto"] = -1] = "auto";
|
|
8
9
|
OSFlags[OSFlags["FAT"] = 0] = "FAT";
|
|
9
10
|
OSFlags[OSFlags["Unix"] = 3] = "Unix";
|
|
10
11
|
OSFlags[OSFlags["HPFS"] = 6] = "HPFS";
|
|
@@ -22,8 +23,13 @@ export async function compressFile(file, os) {
|
|
|
22
23
|
return targetFile;
|
|
23
24
|
}
|
|
24
25
|
export async function compress(buf, os) {
|
|
25
|
-
|
|
26
|
-
|
|
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;
|
|
27
33
|
zBuf[OSSystemIDOffset] = osFlag;
|
|
28
34
|
return zBuf;
|
|
29
35
|
}
|
package/dist/gzip/index.d.ts
CHANGED
package/dist/gzip/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cspell/cspell-tools",
|
|
3
|
-
"version": "7.3.
|
|
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.
|
|
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.
|
|
54
|
+
"cspell-trie-lib": "7.3.2",
|
|
55
55
|
"gensequence": "^5.0.2",
|
|
56
56
|
"glob": "^10.3.4",
|
|
57
|
-
"hunspell-reader": "7.3.
|
|
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": "
|
|
71
|
+
"gitHead": "71d88d4e4d2252124a952c78d4fc03ce0a6d67e3"
|
|
72
72
|
}
|