cspell-io 6.4.2 → 6.5.0
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/CSpellIO.d.ts +11 -0
- package/dist/CSpellIO.js +3 -0
- package/dist/CSpellIONode.d.ts +15 -0
- package/dist/CSpellIONode.js +63 -0
- package/dist/CSpellIOWeb.d.ts +11 -0
- package/dist/CSpellIOWeb.js +27 -0
- package/dist/common/stat.d.ts +9 -0
- package/dist/common/stat.js +19 -0
- package/dist/errors/ErrorNotImplemented.d.ts +5 -0
- package/dist/errors/ErrorNotImplemented.js +11 -0
- package/dist/errors/error.d.ts +2 -0
- package/dist/errors/error.js +14 -0
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.js +8 -0
- package/dist/file/index.d.ts +3 -4
- package/dist/file/index.js +10 -10
- package/dist/handlers/node/file.d.ts +3 -0
- package/dist/handlers/node/file.js +127 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +14 -16
- package/dist/models/BufferEncoding.d.ts +2 -0
- package/dist/models/BufferEncoding.js +3 -0
- package/dist/models/Stats.d.ts +18 -0
- package/dist/models/Stats.js +6 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +3 -0
- package/dist/node/dataUrl.d.ts +22 -0
- package/dist/node/dataUrl.js +62 -0
- package/dist/{file → node/file}/FetchError.d.ts +0 -0
- package/dist/{file → node/file}/FetchError.js +0 -0
- package/dist/{file → node/file}/fetch.d.ts +2 -0
- package/dist/{file → node/file}/fetch.js +10 -1
- package/dist/{file → node/file}/fileReader.d.ts +0 -0
- package/dist/{file → node/file}/fileReader.js +0 -0
- package/dist/{file → node/file}/fileWriter.d.ts +0 -0
- package/dist/{file → node/file}/fileWriter.js +0 -0
- package/dist/node/file/index.d.ts +4 -0
- package/dist/node/file/index.js +14 -0
- package/dist/node/file/stat.d.ts +6 -0
- package/dist/{file → node/file}/stat.js +13 -7
- package/dist/{file → node/file}/util.d.ts +0 -1
- package/dist/{file → node/file}/util.js +6 -2
- package/dist/requests/RequestFsReadBinaryFile.d.ts +9 -0
- package/dist/requests/RequestFsReadBinaryFile.js +9 -0
- package/dist/requests/RequestFsReadFile.d.ts +9 -0
- package/dist/requests/RequestFsReadFile.js +7 -0
- package/dist/requests/RequestFsReadFileSync.d.ts +9 -0
- package/dist/requests/RequestFsReadFileSync.js +7 -0
- package/dist/requests/RequestFsStat.d.ts +9 -0
- package/dist/requests/RequestFsStat.js +9 -0
- package/dist/requests/RequestFsWriteFile.d.ts +8 -0
- package/dist/requests/RequestFsWriteFile.js +7 -0
- package/dist/requests/RequestZlibInflate.d.ts +7 -0
- package/dist/requests/RequestZlibInflate.js +7 -0
- package/dist/requests/index.d.ts +7 -0
- package/dist/requests/index.js +18 -0
- package/dist/test/helper.d.ts +13 -0
- package/dist/test/helper.js +65 -0
- package/package.json +3 -2
- package/dist/file/stat.d.ts +0 -13
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BufferEncoding } from './models/BufferEncoding';
|
|
2
|
+
import type { Stats } from './models';
|
|
3
|
+
export interface CSpellIO {
|
|
4
|
+
readFile(uriOrFilename: string, encoding?: BufferEncoding): Promise<string>;
|
|
5
|
+
readFileSync(uriOrFilename: string, encoding?: BufferEncoding): string;
|
|
6
|
+
writeFile(uriOrFilename: string, content: string): Promise<void>;
|
|
7
|
+
getStat(uriOrFilename: string): Promise<Stats>;
|
|
8
|
+
getStatSync(uriOrFilename: string): Stats;
|
|
9
|
+
compareStats(left: Stats, right: Stats): number;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CSpellIO.d.ts.map
|
package/dist/CSpellIO.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ServiceBus } from '@cspell/cspell-service-bus';
|
|
3
|
+
import { CSpellIO } from './CSpellIO';
|
|
4
|
+
import { Stats } from './models/Stats';
|
|
5
|
+
export declare class CSpellIONode implements CSpellIO {
|
|
6
|
+
readonly serviceBus: ServiceBus;
|
|
7
|
+
constructor(serviceBus?: ServiceBus);
|
|
8
|
+
readFile(uriOrFilename: string, encoding?: BufferEncoding): Promise<string>;
|
|
9
|
+
readFileSync(uriOrFilename: string, encoding?: BufferEncoding): string;
|
|
10
|
+
writeFile(uriOrFilename: string, content: string): Promise<void>;
|
|
11
|
+
getStat(uriOrFilename: string): Promise<Stats>;
|
|
12
|
+
getStatSync(uriOrFilename: string): Stats;
|
|
13
|
+
compareStats(left: Stats, right: Stats): number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=CSpellIONode.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CSpellIONode = void 0;
|
|
4
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
5
|
+
const stat_1 = require("./common/stat");
|
|
6
|
+
const ErrorNotImplemented_1 = require("./errors/ErrorNotImplemented");
|
|
7
|
+
const file_1 = require("./handlers/node/file");
|
|
8
|
+
const util_1 = require("./node/file/util");
|
|
9
|
+
const requests_1 = require("./requests");
|
|
10
|
+
class CSpellIONode {
|
|
11
|
+
constructor(serviceBus = new cspell_service_bus_1.ServiceBus()) {
|
|
12
|
+
this.serviceBus = serviceBus;
|
|
13
|
+
(0, file_1.registerHandlers)(serviceBus);
|
|
14
|
+
}
|
|
15
|
+
readFile(uriOrFilename, encoding = 'utf8') {
|
|
16
|
+
const url = (0, util_1.toURL)(uriOrFilename);
|
|
17
|
+
const res = this.serviceBus.dispatch(requests_1.RequestFsReadFile.create({ url, encoding }));
|
|
18
|
+
if (!(0, cspell_service_bus_1.isServiceResponseSuccess)(res)) {
|
|
19
|
+
throw genError(res.error, 'readFile');
|
|
20
|
+
}
|
|
21
|
+
return res.value;
|
|
22
|
+
}
|
|
23
|
+
readFileSync(uriOrFilename, encoding = 'utf8') {
|
|
24
|
+
const url = (0, util_1.toURL)(uriOrFilename);
|
|
25
|
+
const res = this.serviceBus.dispatch(requests_1.RequestFsReadFileSync.create({ url, encoding }));
|
|
26
|
+
if (!(0, cspell_service_bus_1.isServiceResponseSuccess)(res)) {
|
|
27
|
+
throw genError(res.error, 'readFileSync');
|
|
28
|
+
}
|
|
29
|
+
return res.value;
|
|
30
|
+
}
|
|
31
|
+
writeFile(uriOrFilename, content) {
|
|
32
|
+
const url = (0, util_1.toURL)(uriOrFilename);
|
|
33
|
+
const res = this.serviceBus.dispatch(requests_1.RequestFsWriteFile.create({ url, content }));
|
|
34
|
+
if (!(0, cspell_service_bus_1.isServiceResponseSuccess)(res)) {
|
|
35
|
+
throw genError(res.error, 'writeFile');
|
|
36
|
+
}
|
|
37
|
+
return res.value;
|
|
38
|
+
}
|
|
39
|
+
getStat(uriOrFilename) {
|
|
40
|
+
const url = (0, util_1.toURL)(uriOrFilename);
|
|
41
|
+
const res = this.serviceBus.dispatch(requests_1.RequestFsStat.create({ url }));
|
|
42
|
+
if (!(0, cspell_service_bus_1.isServiceResponseSuccess)(res)) {
|
|
43
|
+
throw genError(res.error, 'getStat');
|
|
44
|
+
}
|
|
45
|
+
return res.value;
|
|
46
|
+
}
|
|
47
|
+
getStatSync(uriOrFilename) {
|
|
48
|
+
const url = (0, util_1.toURL)(uriOrFilename);
|
|
49
|
+
const res = this.serviceBus.dispatch(requests_1.RequestFsStatSync.create({ url }));
|
|
50
|
+
if (!(0, cspell_service_bus_1.isServiceResponseSuccess)(res)) {
|
|
51
|
+
throw genError(res.error, 'getStatSync');
|
|
52
|
+
}
|
|
53
|
+
return res.value;
|
|
54
|
+
}
|
|
55
|
+
compareStats(left, right) {
|
|
56
|
+
return (0, stat_1.compareStats)(left, right);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.CSpellIONode = CSpellIONode;
|
|
60
|
+
function genError(err, alt) {
|
|
61
|
+
return err || new ErrorNotImplemented_1.ErrorNotImplemented(alt);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=CSpellIONode.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CSpellIO } from './CSpellIO';
|
|
2
|
+
import { Stats } from './models/Stats';
|
|
3
|
+
export declare class CSpellIOWeb implements CSpellIO {
|
|
4
|
+
readFile(_uriOrFilename: string): Promise<string>;
|
|
5
|
+
readFileSync(_uriOrFilename: string): string;
|
|
6
|
+
writeFile(_uriOrFilename: string, _content: string): Promise<void>;
|
|
7
|
+
getStat(_uriOrFilename: string): Promise<Stats>;
|
|
8
|
+
getStatSync(_uriOrFilename: string): Stats;
|
|
9
|
+
compareStats(left: Stats, right: Stats): number;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CSpellIOWeb.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CSpellIOWeb = void 0;
|
|
4
|
+
const ErrorNotImplemented_1 = require("./errors/ErrorNotImplemented");
|
|
5
|
+
const stat_1 = require("./common/stat");
|
|
6
|
+
class CSpellIOWeb {
|
|
7
|
+
readFile(_uriOrFilename) {
|
|
8
|
+
throw new ErrorNotImplemented_1.ErrorNotImplemented('readFile');
|
|
9
|
+
}
|
|
10
|
+
readFileSync(_uriOrFilename) {
|
|
11
|
+
throw new ErrorNotImplemented_1.ErrorNotImplemented('readFileSync');
|
|
12
|
+
}
|
|
13
|
+
writeFile(_uriOrFilename, _content) {
|
|
14
|
+
throw new ErrorNotImplemented_1.ErrorNotImplemented('writeFile');
|
|
15
|
+
}
|
|
16
|
+
getStat(_uriOrFilename) {
|
|
17
|
+
throw new ErrorNotImplemented_1.ErrorNotImplemented('getStat');
|
|
18
|
+
}
|
|
19
|
+
getStatSync(_uriOrFilename) {
|
|
20
|
+
throw new ErrorNotImplemented_1.ErrorNotImplemented('getStatSync');
|
|
21
|
+
}
|
|
22
|
+
compareStats(left, right) {
|
|
23
|
+
return (0, stat_1.compareStats)(left, right);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.CSpellIOWeb = CSpellIOWeb;
|
|
27
|
+
//# sourceMappingURL=CSpellIOWeb.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Stats } from '../models/Stats';
|
|
2
|
+
/**
|
|
3
|
+
* Compare two Stats to see if they have the same value.
|
|
4
|
+
* @param left - Stats
|
|
5
|
+
* @param right - Stats
|
|
6
|
+
* @returns 0 - equal; 1 - left > right; -1 left < right
|
|
7
|
+
*/
|
|
8
|
+
export declare function compareStats(left: Stats, right: Stats): number;
|
|
9
|
+
//# sourceMappingURL=stat.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareStats = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Compare two Stats to see if they have the same value.
|
|
6
|
+
* @param left - Stats
|
|
7
|
+
* @param right - Stats
|
|
8
|
+
* @returns 0 - equal; 1 - left > right; -1 left < right
|
|
9
|
+
*/
|
|
10
|
+
function compareStats(left, right) {
|
|
11
|
+
if (left === right)
|
|
12
|
+
return 0;
|
|
13
|
+
if (left.eTag || right.eTag)
|
|
14
|
+
return left.eTag === right.eTag ? 0 : (left.eTag || '') < (right.eTag || '') ? -1 : 1;
|
|
15
|
+
const diff = left.size - right.size || left.mtimeMs - right.mtimeMs;
|
|
16
|
+
return diff < 0 ? -1 : diff > 0 ? 1 : 0;
|
|
17
|
+
}
|
|
18
|
+
exports.compareStats = compareStats;
|
|
19
|
+
//# sourceMappingURL=stat.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorNotImplemented = void 0;
|
|
4
|
+
class ErrorNotImplemented extends Error {
|
|
5
|
+
constructor(method) {
|
|
6
|
+
super(`Method ${method} is not supported.`);
|
|
7
|
+
this.method = method;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ErrorNotImplemented = ErrorNotImplemented;
|
|
11
|
+
//# sourceMappingURL=ErrorNotImplemented.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toError = void 0;
|
|
4
|
+
function toError(e) {
|
|
5
|
+
if (e instanceof Error)
|
|
6
|
+
return e;
|
|
7
|
+
if (typeof e === 'object' && e && typeof e.message === 'string') {
|
|
8
|
+
return e;
|
|
9
|
+
}
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
return Error(e && e.toString());
|
|
12
|
+
}
|
|
13
|
+
exports.toError = toError;
|
|
14
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorNotImplemented = exports.toError = void 0;
|
|
4
|
+
var error_1 = require("./error");
|
|
5
|
+
Object.defineProperty(exports, "toError", { enumerable: true, get: function () { return error_1.toError; } });
|
|
6
|
+
var ErrorNotImplemented_1 = require("./ErrorNotImplemented");
|
|
7
|
+
Object.defineProperty(exports, "ErrorNotImplemented", { enumerable: true, get: function () { return ErrorNotImplemented_1.ErrorNotImplemented; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/dist/file/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { readFile, readFileSync } from '
|
|
2
|
-
export { writeToFile, writeToFileIterable, writeToFileIterableP } from '
|
|
3
|
-
export { getStat, getStatSync } from '
|
|
4
|
-
export type { Stats } from './stat';
|
|
1
|
+
export { readFile, readFileSync } from './../node/file';
|
|
2
|
+
export { writeToFile, writeToFileIterable, writeToFileIterableP } from './../node/file';
|
|
3
|
+
export { getStat, getStatSync } from './../node/file';
|
|
5
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/file/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getStatSync = exports.getStat = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = exports.readFileSync = exports.readFile = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return
|
|
6
|
-
Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return
|
|
9
|
-
Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "getStat", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "getStatSync", { enumerable: true, get: function () { return
|
|
4
|
+
var file_1 = require("./../node/file");
|
|
5
|
+
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return file_1.readFile; } });
|
|
6
|
+
Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return file_1.readFileSync; } });
|
|
7
|
+
var file_2 = require("./../node/file");
|
|
8
|
+
Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return file_2.writeToFile; } });
|
|
9
|
+
Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return file_2.writeToFileIterable; } });
|
|
10
|
+
Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return file_2.writeToFileIterableP; } });
|
|
11
|
+
var file_3 = require("./../node/file");
|
|
12
|
+
Object.defineProperty(exports, "getStat", { enumerable: true, get: function () { return file_3.getStat; } });
|
|
13
|
+
Object.defineProperty(exports, "getStatSync", { enumerable: true, get: function () { return file_3.getStatSync; } });
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerHandlers = void 0;
|
|
7
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const zlib_1 = require("zlib");
|
|
11
|
+
const errors_1 = require("../../errors");
|
|
12
|
+
const fetch_1 = require("../../node/file/fetch");
|
|
13
|
+
const stat_1 = require("../../node/file/stat");
|
|
14
|
+
const requests_1 = require("../../requests");
|
|
15
|
+
const isGzFileRegExp = /\.gz($|[?#])/;
|
|
16
|
+
function isGzFile(url) {
|
|
17
|
+
return isGzFileRegExp.test(url.pathname);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Handle Binary File Reads
|
|
21
|
+
*/
|
|
22
|
+
const handleRequestFsReadBinaryFile = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsReadBinaryFile, ({ params }) => (0, cspell_service_bus_1.createResponse)(fs_1.promises.readFile(params.url)), undefined, 'Node: Read Binary File.');
|
|
23
|
+
/**
|
|
24
|
+
* Handle Binary File Sync Reads
|
|
25
|
+
*/
|
|
26
|
+
const handleRequestFsReadBinaryFileSync = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsReadBinaryFileSync, ({ params }) => (0, cspell_service_bus_1.createResponse)((0, fs_1.readFileSync)(params.url)), undefined, 'Node: Sync Read Binary File.');
|
|
27
|
+
/**
|
|
28
|
+
* Handle UTF-8 Text File Reads
|
|
29
|
+
*/
|
|
30
|
+
const handleRequestFsReadFile = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsReadFile, (req, _, dispatcher) => {
|
|
31
|
+
const { url, encoding } = req.params;
|
|
32
|
+
const res = dispatcher.dispatch(requests_1.RequestFsReadBinaryFile.create({ url }));
|
|
33
|
+
if (!(0, cspell_service_bus_1.isServiceResponseSuccess)(res)) {
|
|
34
|
+
(0, assert_1.default)((0, cspell_service_bus_1.isServiceResponseFailure)(res));
|
|
35
|
+
return (0, cspell_service_bus_1.createResponseFail)(req, res.error);
|
|
36
|
+
}
|
|
37
|
+
return (0, cspell_service_bus_1.createResponse)(res.value.then((buf) => bufferToText(buf, encoding)));
|
|
38
|
+
}, undefined, 'Node: Read Text File.');
|
|
39
|
+
/**
|
|
40
|
+
* Handle UTF-8 Text File Reads
|
|
41
|
+
*/
|
|
42
|
+
const handleRequestFsReadFileSync = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsReadFileSync, (req, _, dispatcher) => {
|
|
43
|
+
const { url, encoding } = req.params;
|
|
44
|
+
const res = dispatcher.dispatch(requests_1.RequestFsReadBinaryFileSync.create({ url }));
|
|
45
|
+
if (!(0, cspell_service_bus_1.isServiceResponseSuccess)(res)) {
|
|
46
|
+
(0, assert_1.default)((0, cspell_service_bus_1.isServiceResponseFailure)(res));
|
|
47
|
+
return (0, cspell_service_bus_1.createResponseFail)(req, res.error);
|
|
48
|
+
}
|
|
49
|
+
return (0, cspell_service_bus_1.createResponse)(bufferToText(res.value, encoding));
|
|
50
|
+
}, undefined, 'Node: Sync Read Text File.');
|
|
51
|
+
/**
|
|
52
|
+
* Handle deflating gzip data
|
|
53
|
+
*/
|
|
54
|
+
const handleRequestZlibInflate = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestZlibInflate, ({ params }) => (0, cspell_service_bus_1.createResponse)((0, zlib_1.gunzipSync)(params.data).toString('utf-8')), undefined, 'Node: gz deflate.');
|
|
55
|
+
const supportedFetchProtocols = { 'http:': true, 'https:': true };
|
|
56
|
+
/**
|
|
57
|
+
* Handle reading gzip'ed text files.
|
|
58
|
+
*/
|
|
59
|
+
const handleRequestFsReadBinaryFileHttp = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsReadBinaryFile, (req, next) => {
|
|
60
|
+
const { url } = req.params;
|
|
61
|
+
if (!(url.protocol in supportedFetchProtocols))
|
|
62
|
+
return next(req);
|
|
63
|
+
return (0, cspell_service_bus_1.createResponse)((0, fetch_1.fetchURL)(url));
|
|
64
|
+
}, undefined, 'Node: Read Http(s) file.');
|
|
65
|
+
function bufferToText(buf, encoding) {
|
|
66
|
+
return buf[0] === 0x1f && buf[1] === 0x8b ? bufferToText((0, zlib_1.gunzipSync)(buf), encoding) : buf.toString(encoding);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle fs:stat
|
|
70
|
+
*/
|
|
71
|
+
const handleRequestFsStat = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsStat, ({ params }) => (0, cspell_service_bus_1.createResponse)(fs_1.promises.stat(params.url)), undefined, 'Node: fs.stat.');
|
|
72
|
+
/**
|
|
73
|
+
* Handle fs:statSync
|
|
74
|
+
*/
|
|
75
|
+
const handleRequestFsStatSync = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsStatSync, (req) => {
|
|
76
|
+
const { params } = req;
|
|
77
|
+
try {
|
|
78
|
+
return (0, cspell_service_bus_1.createResponse)((0, fs_1.statSync)(params.url));
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
return (0, cspell_service_bus_1.createResponseFail)(req, (0, errors_1.toError)(e));
|
|
82
|
+
}
|
|
83
|
+
}, undefined, 'Node: fs.stat.');
|
|
84
|
+
/**
|
|
85
|
+
* Handle deflating gzip data
|
|
86
|
+
*/
|
|
87
|
+
const handleRequestFsStatHttp = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsStat, (req, next) => {
|
|
88
|
+
const { url } = req.params;
|
|
89
|
+
if (!(url.protocol in supportedFetchProtocols))
|
|
90
|
+
return next(req);
|
|
91
|
+
return (0, cspell_service_bus_1.createResponse)((0, stat_1.getStatHttp)(url));
|
|
92
|
+
}, undefined, 'Node: http get stat');
|
|
93
|
+
/**
|
|
94
|
+
* Handle fs:writeFile
|
|
95
|
+
*/
|
|
96
|
+
const handleRequestFsWriteFile = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsWriteFile, ({ params }) => (0, cspell_service_bus_1.createResponse)(fs_1.promises.writeFile(params.url, params.content)), undefined, 'Node: fs.writeFile');
|
|
97
|
+
/**
|
|
98
|
+
* Handle fs:writeFile compressed
|
|
99
|
+
*/
|
|
100
|
+
const handleRequestFsWriteFileGz = (0, cspell_service_bus_1.createRequestHandler)(requests_1.RequestFsWriteFile, (req, next) => {
|
|
101
|
+
const { url, content } = req.params;
|
|
102
|
+
if (!isGzFile(url))
|
|
103
|
+
return next(req);
|
|
104
|
+
return (0, cspell_service_bus_1.createResponse)(fs_1.promises.writeFile(url, (0, zlib_1.gzipSync)(content)));
|
|
105
|
+
}, undefined, 'Node: http get stat');
|
|
106
|
+
function registerHandlers(serviceBus) {
|
|
107
|
+
/**
|
|
108
|
+
* Handlers are in order of low to high level
|
|
109
|
+
* Order is VERY important.
|
|
110
|
+
*/
|
|
111
|
+
const handlers = [
|
|
112
|
+
handleRequestFsWriteFile,
|
|
113
|
+
handleRequestFsWriteFileGz,
|
|
114
|
+
handleRequestFsReadBinaryFile,
|
|
115
|
+
handleRequestFsReadBinaryFileSync,
|
|
116
|
+
handleRequestFsReadBinaryFileHttp,
|
|
117
|
+
handleRequestFsReadFile,
|
|
118
|
+
handleRequestFsReadFileSync,
|
|
119
|
+
handleRequestZlibInflate,
|
|
120
|
+
handleRequestFsStatSync,
|
|
121
|
+
handleRequestFsStat,
|
|
122
|
+
handleRequestFsStatHttp,
|
|
123
|
+
];
|
|
124
|
+
handlers.forEach((handler) => serviceBus.addHandler(handler));
|
|
125
|
+
}
|
|
126
|
+
exports.registerHandlers = registerHandlers;
|
|
127
|
+
//# sourceMappingURL=file.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
export * from './file';
|
|
2
1
|
export { toArray as asyncIterableToArray } from './async/asyncIterable';
|
|
2
|
+
export { getStat, getStatSync, readFile, readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file';
|
|
3
|
+
export type { Stats } from './models/Stats';
|
|
4
|
+
export type { CSpellIO } from './CSpellIO';
|
|
5
|
+
export { CSpellIONode } from './CSpellIONode';
|
|
6
|
+
export { encodeDataUrl, toDataUrl } from './node/dataUrl';
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.asyncIterableToArray = void 0;
|
|
18
|
-
__exportStar(require("./file"), exports);
|
|
3
|
+
exports.toDataUrl = exports.encodeDataUrl = exports.CSpellIONode = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = exports.readFileSync = exports.readFile = exports.getStatSync = exports.getStat = exports.asyncIterableToArray = void 0;
|
|
19
4
|
var asyncIterable_1 = require("./async/asyncIterable");
|
|
20
5
|
Object.defineProperty(exports, "asyncIterableToArray", { enumerable: true, get: function () { return asyncIterable_1.toArray; } });
|
|
6
|
+
var file_1 = require("./file");
|
|
7
|
+
Object.defineProperty(exports, "getStat", { enumerable: true, get: function () { return file_1.getStat; } });
|
|
8
|
+
Object.defineProperty(exports, "getStatSync", { enumerable: true, get: function () { return file_1.getStatSync; } });
|
|
9
|
+
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return file_1.readFile; } });
|
|
10
|
+
Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return file_1.readFileSync; } });
|
|
11
|
+
Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return file_1.writeToFile; } });
|
|
12
|
+
Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return file_1.writeToFileIterable; } });
|
|
13
|
+
Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return file_1.writeToFileIterableP; } });
|
|
14
|
+
var CSpellIONode_1 = require("./CSpellIONode");
|
|
15
|
+
Object.defineProperty(exports, "CSpellIONode", { enumerable: true, get: function () { return CSpellIONode_1.CSpellIONode; } });
|
|
16
|
+
var dataUrl_1 = require("./node/dataUrl");
|
|
17
|
+
Object.defineProperty(exports, "encodeDataUrl", { enumerable: true, get: function () { return dataUrl_1.encodeDataUrl; } });
|
|
18
|
+
Object.defineProperty(exports, "toDataUrl", { enumerable: true, get: function () { return dataUrl_1.toDataUrl; } });
|
|
21
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subset of definition from the Node definition to avoid a dependency upon a specific version of Node
|
|
3
|
+
*/
|
|
4
|
+
export interface Stats {
|
|
5
|
+
/**
|
|
6
|
+
* Size of file in byes, -1 if unknown.
|
|
7
|
+
*/
|
|
8
|
+
size: number;
|
|
9
|
+
/**
|
|
10
|
+
* Modification time, 0 if unknown.
|
|
11
|
+
*/
|
|
12
|
+
mtimeMs: number;
|
|
13
|
+
/**
|
|
14
|
+
* Used by web requests to see if a resource has changed.
|
|
15
|
+
*/
|
|
16
|
+
eTag?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Stats.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/**
|
|
4
|
+
* Generates a string of the following format:
|
|
5
|
+
*
|
|
6
|
+
* `data:[mediaType][;charset=<encoding>[;base64],<data>`
|
|
7
|
+
*
|
|
8
|
+
* - `encoding` - defaults to `utf8` for text data
|
|
9
|
+
* @param data
|
|
10
|
+
* @param mediaType - The mediaType is a [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type string
|
|
11
|
+
* @param attributes - Additional attributes
|
|
12
|
+
*/
|
|
13
|
+
export declare function encodeDataUrl(data: string | Buffer, mediaType: string, attributes?: Iterable<readonly [string, string]> | undefined): string;
|
|
14
|
+
export declare function toDataUrl(data: string | Buffer, mediaType: string, attributes?: Iterable<[string, string]> | undefined): URL;
|
|
15
|
+
export interface DecodedDataUrl {
|
|
16
|
+
data: Buffer;
|
|
17
|
+
mediaType: string;
|
|
18
|
+
encoding?: string | undefined;
|
|
19
|
+
attributes: Map<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export declare function decodeDataUrl(url: string): DecodedDataUrl;
|
|
22
|
+
//# sourceMappingURL=dataUrl.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeDataUrl = exports.toDataUrl = exports.encodeDataUrl = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generates a string of the following format:
|
|
6
|
+
*
|
|
7
|
+
* `data:[mediaType][;charset=<encoding>[;base64],<data>`
|
|
8
|
+
*
|
|
9
|
+
* - `encoding` - defaults to `utf8` for text data
|
|
10
|
+
* @param data
|
|
11
|
+
* @param mediaType - The mediaType is a [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type string
|
|
12
|
+
* @param attributes - Additional attributes
|
|
13
|
+
*/
|
|
14
|
+
function encodeDataUrl(data, mediaType, attributes) {
|
|
15
|
+
if (typeof data === 'string')
|
|
16
|
+
return encodeString(data, mediaType, attributes);
|
|
17
|
+
const attribs = encodeAttributes(attributes || []);
|
|
18
|
+
return `data:${mediaType}${attribs};base64,${data.toString('base64url')}`;
|
|
19
|
+
}
|
|
20
|
+
exports.encodeDataUrl = encodeDataUrl;
|
|
21
|
+
function toDataUrl(data, mediaType, attributes) {
|
|
22
|
+
return new URL(encodeDataUrl(data, mediaType, attributes));
|
|
23
|
+
}
|
|
24
|
+
exports.toDataUrl = toDataUrl;
|
|
25
|
+
function encodeString(data, mediaType, attributes) {
|
|
26
|
+
mediaType = mediaType || 'text/plain';
|
|
27
|
+
attributes = attributes || [];
|
|
28
|
+
const asUrlComp = encodeURIComponent(data);
|
|
29
|
+
const asBase64 = Buffer.from(data).toString('base64url');
|
|
30
|
+
const useBase64 = asBase64.length < asUrlComp.length - 7;
|
|
31
|
+
const encoded = useBase64 ? asBase64 : asUrlComp;
|
|
32
|
+
// Ensure charset is first.
|
|
33
|
+
const attribMap = new Map([['charset', 'utf8']].concat([...attributes]));
|
|
34
|
+
attribMap.set('charset', 'utf8'); // Make sure it is always `utf8`.
|
|
35
|
+
const attribs = encodeAttributes(attribMap);
|
|
36
|
+
return `data:${mediaType}${attribs}${useBase64 ? ';base64' : ''},${encoded}`;
|
|
37
|
+
}
|
|
38
|
+
function encodeAttributes(attributes) {
|
|
39
|
+
return [...attributes].map(([key, value]) => `;${key}=${encodeURIComponent(value)}`).join('');
|
|
40
|
+
}
|
|
41
|
+
const dataUrlRegExHead = /^data:(?<mediaType>[^;,]*)(?<attributes>(?:;[^=]+=[^;,]*)*)(?<base64>;base64)?$/;
|
|
42
|
+
function decodeDataUrl(url) {
|
|
43
|
+
const [head, encodedData] = url.split(',', 2);
|
|
44
|
+
if (!head || encodedData === undefined)
|
|
45
|
+
throw Error('Not a data url');
|
|
46
|
+
const match = head.match(dataUrlRegExHead);
|
|
47
|
+
if (!match || !match.groups)
|
|
48
|
+
throw Error('Not a data url');
|
|
49
|
+
const mediaType = match.groups['mediaType'] || '';
|
|
50
|
+
const rawAttributes = (match.groups['attributes'] || '')
|
|
51
|
+
.split(';')
|
|
52
|
+
.filter((a) => !!a)
|
|
53
|
+
.map((entry) => entry.split('=', 2))
|
|
54
|
+
.map(([key, value]) => [key, decodeURIComponent(value)]);
|
|
55
|
+
const attributes = new Map(rawAttributes);
|
|
56
|
+
const encoding = attributes.get('charset');
|
|
57
|
+
const isBase64 = !!match.groups['base64'];
|
|
58
|
+
const data = isBase64 ? Buffer.from(encodedData, 'base64url') : Buffer.from(decodeURIComponent(encodedData));
|
|
59
|
+
return { mediaType, data, encoding, attributes };
|
|
60
|
+
}
|
|
61
|
+
exports.decodeDataUrl = decodeDataUrl;
|
|
62
|
+
//# sourceMappingURL=dataUrl.js.map
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { Headers } from 'node-fetch';
|
|
3
4
|
import nodeFetch from 'node-fetch';
|
|
4
5
|
export declare const fetch: typeof nodeFetch;
|
|
5
6
|
export declare function fetchHead(request: string | URL): Promise<Headers>;
|
|
7
|
+
export declare function fetchURL(url: URL): Promise<Buffer>;
|
|
6
8
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -3,12 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchHead = exports.fetch = void 0;
|
|
6
|
+
exports.fetchURL = exports.fetchHead = exports.fetch = void 0;
|
|
7
7
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
const FetchError_1 = require("./FetchError");
|
|
8
9
|
exports.fetch = node_fetch_1.default;
|
|
9
10
|
async function fetchHead(request) {
|
|
10
11
|
const r = await (0, exports.fetch)(request, { method: 'HEAD' });
|
|
11
12
|
return r.headers;
|
|
12
13
|
}
|
|
13
14
|
exports.fetchHead = fetchHead;
|
|
15
|
+
async function fetchURL(url) {
|
|
16
|
+
const response = await (0, exports.fetch)(url);
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw FetchError_1.FetchUrlError.create(url, response.status);
|
|
19
|
+
}
|
|
20
|
+
return Buffer.from(await response.arrayBuffer());
|
|
21
|
+
}
|
|
22
|
+
exports.fetchURL = fetchURL;
|
|
14
23
|
//# sourceMappingURL=fetch.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStatSync = exports.getStat = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = exports.readFileSync = exports.readFile = void 0;
|
|
4
|
+
var fileReader_1 = require("./fileReader");
|
|
5
|
+
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return fileReader_1.readFile; } });
|
|
6
|
+
Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return fileReader_1.readFileSync; } });
|
|
7
|
+
var fileWriter_1 = require("./fileWriter");
|
|
8
|
+
Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return fileWriter_1.writeToFile; } });
|
|
9
|
+
Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return fileWriter_1.writeToFileIterable; } });
|
|
10
|
+
Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return fileWriter_1.writeToFileIterableP; } });
|
|
11
|
+
var stat_1 = require("./stat");
|
|
12
|
+
Object.defineProperty(exports, "getStat", { enumerable: true, get: function () { return stat_1.getStat; } });
|
|
13
|
+
Object.defineProperty(exports, "getStatSync", { enumerable: true, get: function () { return stat_1.getStatSync; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Stats } from '../../models/Stats';
|
|
3
|
+
export declare function getStat(filenameOrUri: string): Promise<Stats | Error>;
|
|
4
|
+
export declare function getStatSync(uri: string): Stats | Error;
|
|
5
|
+
export declare function getStatHttp(url: URL): Promise<Stats>;
|
|
6
|
+
//# sourceMappingURL=stat.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStatSync = exports.getStat = void 0;
|
|
3
|
+
exports.getStatHttp = exports.getStatSync = exports.getStat = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const util_1 = require("util");
|
|
6
6
|
const fetch_1 = require("./fetch");
|
|
@@ -10,12 +10,7 @@ async function getStat(filenameOrUri) {
|
|
|
10
10
|
const url = (0, util_2.toURL)(filenameOrUri);
|
|
11
11
|
if (!(0, util_2.isFileURL)(url)) {
|
|
12
12
|
try {
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
size: Number.parseInt(headers.get('content-length') || '0', 10),
|
|
16
|
-
mtimeMs: 0,
|
|
17
|
-
eTag: headers.get('etag') || undefined,
|
|
18
|
-
};
|
|
13
|
+
return await getStatHttp(url);
|
|
19
14
|
}
|
|
20
15
|
catch (e) {
|
|
21
16
|
return toError(e);
|
|
@@ -34,6 +29,17 @@ function getStatSync(uri) {
|
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
31
|
exports.getStatSync = getStatSync;
|
|
32
|
+
async function getStatHttp(url) {
|
|
33
|
+
const headers = await (0, fetch_1.fetchHead)(url);
|
|
34
|
+
const eTag = headers.get('etag') || undefined;
|
|
35
|
+
const guessSize = Number.parseInt(headers.get('content-length') || '0', 10);
|
|
36
|
+
return {
|
|
37
|
+
size: eTag ? -1 : guessSize,
|
|
38
|
+
mtimeMs: 0,
|
|
39
|
+
eTag,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.getStatHttp = getStatHttp;
|
|
37
43
|
function toError(e) {
|
|
38
44
|
if (isErrnoException(e) || e instanceof Error)
|
|
39
45
|
return e;
|
|
@@ -11,7 +11,7 @@ function isZipped(filename) {
|
|
|
11
11
|
}
|
|
12
12
|
exports.isZipped = isZipped;
|
|
13
13
|
function isUrlLike(filename) {
|
|
14
|
-
return filename instanceof
|
|
14
|
+
return filename instanceof URL || isURLRegExp.test(filename);
|
|
15
15
|
}
|
|
16
16
|
exports.isUrlLike = isUrlLike;
|
|
17
17
|
function isSupportedURL(url) {
|
|
@@ -23,7 +23,11 @@ function isFileURL(url) {
|
|
|
23
23
|
}
|
|
24
24
|
exports.isFileURL = isFileURL;
|
|
25
25
|
function toURL(filename) {
|
|
26
|
-
return filename instanceof
|
|
26
|
+
return filename instanceof URL || typeof filename !== 'string'
|
|
27
|
+
? filename
|
|
28
|
+
: isUrlLike(filename)
|
|
29
|
+
? new URL(filename)
|
|
30
|
+
: (0, url_1.pathToFileURL)(filename);
|
|
27
31
|
}
|
|
28
32
|
exports.toURL = toURL;
|
|
29
33
|
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
interface RequestParams {
|
|
4
|
+
readonly url: URL;
|
|
5
|
+
}
|
|
6
|
+
export declare const RequestFsReadBinaryFile: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readBinaryFile", RequestParams, Promise<Buffer>>, RequestParams, "fs:readBinaryFile">;
|
|
7
|
+
export declare const RequestFsReadBinaryFileSync: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readBinaryFileSync", RequestParams, Buffer>, RequestParams, "fs:readBinaryFileSync">;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=RequestFsReadBinaryFile.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestFsReadBinaryFileSync = exports.RequestFsReadBinaryFile = void 0;
|
|
4
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
5
|
+
const RequestType = 'fs:readBinaryFile';
|
|
6
|
+
exports.RequestFsReadBinaryFile = (0, cspell_service_bus_1.requestFactory)(RequestType);
|
|
7
|
+
const RequestTypeSync = 'fs:readBinaryFileSync';
|
|
8
|
+
exports.RequestFsReadBinaryFileSync = (0, cspell_service_bus_1.requestFactory)(RequestTypeSync);
|
|
9
|
+
//# sourceMappingURL=RequestFsReadBinaryFile.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
interface RequestParams {
|
|
4
|
+
readonly url: URL;
|
|
5
|
+
readonly encoding: BufferEncoding;
|
|
6
|
+
}
|
|
7
|
+
export declare const RequestFsReadFile: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<string>>, RequestParams, "fs:readFile">;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=RequestFsReadFile.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestFsReadFile = void 0;
|
|
4
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
5
|
+
const RequestType = 'fs:readFile';
|
|
6
|
+
exports.RequestFsReadFile = (0, cspell_service_bus_1.requestFactory)(RequestType);
|
|
7
|
+
//# sourceMappingURL=RequestFsReadFile.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
interface RequestParams {
|
|
4
|
+
readonly url: URL;
|
|
5
|
+
readonly encoding: BufferEncoding;
|
|
6
|
+
}
|
|
7
|
+
export declare const RequestFsReadFileSync: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, string>, RequestParams, "fs:readFileSync">;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=RequestFsReadFileSync.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestFsReadFileSync = void 0;
|
|
4
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
5
|
+
const RequestType = 'fs:readFileSync';
|
|
6
|
+
exports.RequestFsReadFileSync = (0, cspell_service_bus_1.requestFactory)(RequestType);
|
|
7
|
+
//# sourceMappingURL=RequestFsReadFileSync.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Stats } from '../models';
|
|
3
|
+
interface RequestStatParams {
|
|
4
|
+
readonly url: URL;
|
|
5
|
+
}
|
|
6
|
+
export declare const RequestFsStat: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:stat", RequestStatParams, Promise<Stats>>, RequestStatParams, "fs:stat">;
|
|
7
|
+
export declare const RequestFsStatSync: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:statSync", RequestStatParams, Stats>, RequestStatParams, "fs:statSync">;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=RequestFsStat.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestFsStatSync = exports.RequestFsStat = void 0;
|
|
4
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
5
|
+
const RequestTypeStat = 'fs:stat';
|
|
6
|
+
exports.RequestFsStat = (0, cspell_service_bus_1.requestFactory)(RequestTypeStat);
|
|
7
|
+
const RequestTypeStatSync = 'fs:statSync';
|
|
8
|
+
exports.RequestFsStatSync = (0, cspell_service_bus_1.requestFactory)(RequestTypeStatSync);
|
|
9
|
+
//# sourceMappingURL=RequestFsStat.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
interface RequestParams {
|
|
3
|
+
readonly url: URL;
|
|
4
|
+
readonly content: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const RequestFsWriteFile: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:writeFile", RequestParams, Promise<void>>, RequestParams, "fs:writeFile">;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=RequestFsWriteFile.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestFsWriteFile = void 0;
|
|
4
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
5
|
+
const RequestType = 'fs:writeFile';
|
|
6
|
+
exports.RequestFsWriteFile = (0, cspell_service_bus_1.requestFactory)(RequestType);
|
|
7
|
+
//# sourceMappingURL=RequestFsWriteFile.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
interface RequestParams {
|
|
3
|
+
readonly data: Buffer;
|
|
4
|
+
}
|
|
5
|
+
export declare const RequestZlibInflate: import("@cspell/cspell-service-bus/request").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"zlib:inflate", RequestParams, string>, RequestParams, "zlib:inflate">;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=RequestZlibInflate.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestZlibInflate = void 0;
|
|
4
|
+
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
|
|
5
|
+
const RequestType = 'zlib:inflate';
|
|
6
|
+
exports.RequestZlibInflate = (0, cspell_service_bus_1.requestFactory)(RequestType);
|
|
7
|
+
//# sourceMappingURL=RequestZlibInflate.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync } from './RequestFsReadBinaryFile';
|
|
2
|
+
export { RequestFsReadFile } from './RequestFsReadFile';
|
|
3
|
+
export { RequestFsReadFileSync } from './RequestFsReadFileSync';
|
|
4
|
+
export { RequestFsStat, RequestFsStatSync } from './RequestFsStat';
|
|
5
|
+
export { RequestZlibInflate } from './RequestZlibInflate';
|
|
6
|
+
export { RequestFsWriteFile } from './RequestFsWriteFile';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestFsWriteFile = exports.RequestZlibInflate = exports.RequestFsStatSync = exports.RequestFsStat = exports.RequestFsReadFileSync = exports.RequestFsReadFile = exports.RequestFsReadBinaryFileSync = exports.RequestFsReadBinaryFile = void 0;
|
|
4
|
+
var RequestFsReadBinaryFile_1 = require("./RequestFsReadBinaryFile");
|
|
5
|
+
Object.defineProperty(exports, "RequestFsReadBinaryFile", { enumerable: true, get: function () { return RequestFsReadBinaryFile_1.RequestFsReadBinaryFile; } });
|
|
6
|
+
Object.defineProperty(exports, "RequestFsReadBinaryFileSync", { enumerable: true, get: function () { return RequestFsReadBinaryFile_1.RequestFsReadBinaryFileSync; } });
|
|
7
|
+
var RequestFsReadFile_1 = require("./RequestFsReadFile");
|
|
8
|
+
Object.defineProperty(exports, "RequestFsReadFile", { enumerable: true, get: function () { return RequestFsReadFile_1.RequestFsReadFile; } });
|
|
9
|
+
var RequestFsReadFileSync_1 = require("./RequestFsReadFileSync");
|
|
10
|
+
Object.defineProperty(exports, "RequestFsReadFileSync", { enumerable: true, get: function () { return RequestFsReadFileSync_1.RequestFsReadFileSync; } });
|
|
11
|
+
var RequestFsStat_1 = require("./RequestFsStat");
|
|
12
|
+
Object.defineProperty(exports, "RequestFsStat", { enumerable: true, get: function () { return RequestFsStat_1.RequestFsStat; } });
|
|
13
|
+
Object.defineProperty(exports, "RequestFsStatSync", { enumerable: true, get: function () { return RequestFsStat_1.RequestFsStatSync; } });
|
|
14
|
+
var RequestZlibInflate_1 = require("./RequestZlibInflate");
|
|
15
|
+
Object.defineProperty(exports, "RequestZlibInflate", { enumerable: true, get: function () { return RequestZlibInflate_1.RequestZlibInflate; } });
|
|
16
|
+
var RequestFsWriteFile_1 = require("./RequestFsWriteFile");
|
|
17
|
+
Object.defineProperty(exports, "RequestFsWriteFile", { enumerable: true, get: function () { return RequestFsWriteFile_1.RequestFsWriteFile; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function pathToSample(...parts: string[]): string;
|
|
2
|
+
export declare function pathToRoot(...parts: string[]): string;
|
|
3
|
+
export declare function makePathToFile(file: string): Promise<void>;
|
|
4
|
+
export declare function testNameToDir(testName: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Calculate a Uri for a path to a temporary directory that will be unique to the current test.
|
|
7
|
+
* Note: if a text is not currently running, then it is the path for the test file.
|
|
8
|
+
* @param baseFilename - name of file / directory wanted
|
|
9
|
+
* @param testFilename - optional full path to a test file.
|
|
10
|
+
* @returns full path to the requested temp file.
|
|
11
|
+
*/
|
|
12
|
+
export declare function pathToTemp(...parts: string[]): string;
|
|
13
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.pathToTemp = exports.testNameToDir = exports.makePathToFile = exports.pathToRoot = exports.pathToSample = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const fs_extra_1 = require("fs-extra");
|
|
29
|
+
const pathPackageRoot = path.join(__dirname, '../..');
|
|
30
|
+
const pathSamples = path.join(pathPackageRoot, 'samples');
|
|
31
|
+
const pathTemp = path.join(pathPackageRoot, 'temp');
|
|
32
|
+
function pathToSample(...parts) {
|
|
33
|
+
return path.resolve(pathSamples, ...parts);
|
|
34
|
+
}
|
|
35
|
+
exports.pathToSample = pathToSample;
|
|
36
|
+
function pathToRoot(...parts) {
|
|
37
|
+
return path.resolve(pathPackageRoot, ...parts);
|
|
38
|
+
}
|
|
39
|
+
exports.pathToRoot = pathToRoot;
|
|
40
|
+
function makePathToFile(file) {
|
|
41
|
+
return (0, fs_extra_1.mkdirp)(path.dirname(file));
|
|
42
|
+
}
|
|
43
|
+
exports.makePathToFile = makePathToFile;
|
|
44
|
+
function testNameToDir(testName) {
|
|
45
|
+
return `test_${testName.replace(/\s/g, '-').replace(/[^\w.-]/gi, '_')}_test`;
|
|
46
|
+
}
|
|
47
|
+
exports.testNameToDir = testNameToDir;
|
|
48
|
+
/**
|
|
49
|
+
* Calculate a Uri for a path to a temporary directory that will be unique to the current test.
|
|
50
|
+
* Note: if a text is not currently running, then it is the path for the test file.
|
|
51
|
+
* @param baseFilename - name of file / directory wanted
|
|
52
|
+
* @param testFilename - optional full path to a test file.
|
|
53
|
+
* @returns full path to the requested temp file.
|
|
54
|
+
*/
|
|
55
|
+
function pathToTemp(...parts) {
|
|
56
|
+
const testState = expect.getState();
|
|
57
|
+
const callerFile = testState.testPath || '.';
|
|
58
|
+
const testFile = path.relative(pathPackageRoot, callerFile);
|
|
59
|
+
expect.getState();
|
|
60
|
+
const testName = testState.currentTestName || '.';
|
|
61
|
+
const testDirName = testNameToDir(testName);
|
|
62
|
+
return path.resolve(pathTemp, testFile, testDirName, ...parts);
|
|
63
|
+
}
|
|
64
|
+
exports.pathToTemp = pathToTemp;
|
|
65
|
+
//# sourceMappingURL=helper.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-io",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "A library of useful I/O functions used across various cspell tools.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -46,8 +46,9 @@
|
|
|
46
46
|
"rimraf": "^3.0.2"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
+
"@cspell/cspell-service-bus": "^6.5.0",
|
|
49
50
|
"@types/node-fetch": "^2.6.2",
|
|
50
51
|
"node-fetch": "^2.6.7"
|
|
51
52
|
},
|
|
52
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "65c80b01e17bb0d74b57ef8b29309684a8588e27"
|
|
53
54
|
}
|
package/dist/file/stat.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copied from the Node definition to avoid a dependency upon a specific version of Node
|
|
3
|
-
*/
|
|
4
|
-
interface StatsBase<T> {
|
|
5
|
-
size: T;
|
|
6
|
-
mtimeMs: T;
|
|
7
|
-
eTag?: string | undefined;
|
|
8
|
-
}
|
|
9
|
-
export declare function getStat(filenameOrUri: string): Promise<Stats | Error>;
|
|
10
|
-
export declare function getStatSync(uri: string): Stats | Error;
|
|
11
|
-
export declare type Stats = StatsBase<number>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=stat.d.ts.map
|