cspell-io 7.0.1 → 7.0.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/esm/common/arrayBuffers.d.ts +1 -1
- package/dist/esm/node/dataUrl.d.ts +1 -1
- package/dist/esm/node/file/FetchError.d.ts +1 -1
- package/dist/esm/node/file/fetch.d.ts +3 -4
- package/dist/esm/node/file/fetch.js +5 -1
- package/dist/esm/requests/RequestFsReadFile.d.ts +1 -1
- package/dist/esm/requests/RequestFsReadFileSync.d.ts +1 -1
- package/dist/esm/requests/RequestZlibInflate.d.ts +1 -1
- package/package.json +10 -12
- package/dist/cjs/CSpellIO.d.ts +0 -69
- package/dist/cjs/CSpellIO.js +0 -3
- package/dist/cjs/CSpellIONode.d.ts +0 -20
- package/dist/cjs/CSpellIONode.js +0 -81
- package/dist/cjs/CSpellIOWeb.d.ts +0 -15
- package/dist/cjs/CSpellIOWeb.js +0 -36
- package/dist/cjs/async/asyncIterable.d.ts +0 -6
- package/dist/cjs/async/asyncIterable.js +0 -16
- package/dist/cjs/common/BufferEncoding.d.ts +0 -4
- package/dist/cjs/common/BufferEncoding.js +0 -3
- package/dist/cjs/common/arrayBuffers.d.ts +0 -17
- package/dist/cjs/common/arrayBuffers.js +0 -45
- package/dist/cjs/common/encode-decode.d.ts +0 -11
- package/dist/cjs/common/encode-decode.js +0 -85
- package/dist/cjs/common/stat.d.ts +0 -9
- package/dist/cjs/common/stat.js +0 -19
- package/dist/cjs/common/transformers.d.ts +0 -6
- package/dist/cjs/common/transformers.js +0 -71
- package/dist/cjs/errors/ErrorNotImplemented.d.ts +0 -5
- package/dist/cjs/errors/ErrorNotImplemented.js +0 -11
- package/dist/cjs/errors/error.d.ts +0 -2
- package/dist/cjs/errors/error.js +0 -14
- package/dist/cjs/errors/index.d.ts +0 -3
- package/dist/cjs/errors/index.js +0 -8
- package/dist/cjs/file/file.d.ts +0 -6
- package/dist/cjs/file/file.js +0 -29
- package/dist/cjs/file/index.d.ts +0 -3
- package/dist/cjs/file/index.js +0 -13
- package/dist/cjs/handlers/node/file.d.ts +0 -3
- package/dist/cjs/handlers/node/file.js +0 -173
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/index.js +0 -20
- package/dist/cjs/models/BufferEncoding.d.ts +0 -2
- package/dist/cjs/models/BufferEncoding.js +0 -3
- package/dist/cjs/models/FileResource.d.ts +0 -35
- package/dist/cjs/models/FileResource.js +0 -3
- package/dist/cjs/models/Stats.d.ts +0 -18
- package/dist/cjs/models/Stats.js +0 -6
- package/dist/cjs/models/index.d.ts +0 -2
- package/dist/cjs/models/index.js +0 -3
- package/dist/cjs/node/dataUrl.d.ts +0 -27
- package/dist/cjs/node/dataUrl.js +0 -116
- package/dist/cjs/node/file/FetchError.d.ts +0 -9
- package/dist/cjs/node/file/FetchError.js +0 -21
- package/dist/cjs/node/file/fetch.d.ts +0 -7
- package/dist/cjs/node/file/fetch.js +0 -23
- package/dist/cjs/node/file/fileReader.d.ts +0 -4
- package/dist/cjs/node/file/fileReader.js +0 -91
- package/dist/cjs/node/file/fileWriter.d.ts +0 -4
- package/dist/cjs/node/file/fileWriter.js +0 -43
- package/dist/cjs/node/file/index.d.ts +0 -4
- package/dist/cjs/node/file/index.js +0 -13
- package/dist/cjs/node/file/stat.d.ts +0 -5
- package/dist/cjs/node/file/stat.js +0 -54
- package/dist/cjs/node/file/util.d.ts +0 -9
- package/dist/cjs/node/file/util.js +0 -69
- package/dist/cjs/requests/RequestFsReadBinaryFile.d.ts +0 -11
- package/dist/cjs/requests/RequestFsReadBinaryFile.js +0 -9
- package/dist/cjs/requests/RequestFsReadFile.d.ts +0 -11
- package/dist/cjs/requests/RequestFsReadFile.js +0 -7
- package/dist/cjs/requests/RequestFsReadFileSync.d.ts +0 -11
- package/dist/cjs/requests/RequestFsReadFileSync.js +0 -7
- package/dist/cjs/requests/RequestFsStat.d.ts +0 -11
- package/dist/cjs/requests/RequestFsStat.js +0 -9
- package/dist/cjs/requests/RequestFsWriteFile.d.ts +0 -9
- package/dist/cjs/requests/RequestFsWriteFile.js +0 -7
- package/dist/cjs/requests/RequestZlibInflate.d.ts +0 -9
- package/dist/cjs/requests/RequestZlibInflate.js +0 -7
- package/dist/cjs/requests/index.d.ts +0 -7
- package/dist/cjs/requests/index.js +0 -18
- package/dist/cjs/test/test.helper.d.ts +0 -13
- package/dist/cjs/test/test.helper.js +0 -69
- package/dist/esm/CSpellIO.d.mts +0 -69
- package/dist/esm/CSpellIO.mjs +0 -1
- package/dist/esm/CSpellIONode.d.mts +0 -20
- package/dist/esm/CSpellIONode.mjs +0 -75
- package/dist/esm/CSpellIOWeb.d.mts +0 -15
- package/dist/esm/CSpellIOWeb.mjs +0 -31
- package/dist/esm/async/asyncIterable.d.mts +0 -6
- package/dist/esm/async/asyncIterable.mjs +0 -11
- package/dist/esm/common/BufferEncoding.d.mts +0 -4
- package/dist/esm/common/BufferEncoding.mjs +0 -1
- package/dist/esm/common/arrayBuffers.d.mts +0 -17
- package/dist/esm/common/arrayBuffers.mjs +0 -37
- package/dist/esm/common/encode-decode.d.mts +0 -11
- package/dist/esm/common/encode-decode.mjs +0 -72
- package/dist/esm/common/stat.d.mts +0 -9
- package/dist/esm/common/stat.mjs +0 -14
- package/dist/esm/common/transformers.d.mts +0 -6
- package/dist/esm/common/transformers.mjs +0 -65
- package/dist/esm/errors/ErrorNotImplemented.d.mts +0 -5
- package/dist/esm/errors/ErrorNotImplemented.mjs +0 -6
- package/dist/esm/errors/error.d.mts +0 -2
- package/dist/esm/errors/error.mjs +0 -9
- package/dist/esm/errors/index.d.mts +0 -3
- package/dist/esm/errors/index.mjs +0 -2
- package/dist/esm/file/file.d.mts +0 -6
- package/dist/esm/file/file.mjs +0 -21
- package/dist/esm/file/index.d.mts +0 -3
- package/dist/esm/file/index.mjs +0 -2
- package/dist/esm/handlers/node/file.d.mts +0 -3
- package/dist/esm/handlers/node/file.mjs +0 -165
- package/dist/esm/index.d.mts +0 -7
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/models/BufferEncoding.d.mts +0 -2
- package/dist/esm/models/BufferEncoding.mjs +0 -1
- package/dist/esm/models/FileResource.d.mts +0 -35
- package/dist/esm/models/FileResource.mjs +0 -1
- package/dist/esm/models/Stats.d.mts +0 -18
- package/dist/esm/models/Stats.mjs +0 -4
- package/dist/esm/models/index.d.mts +0 -2
- package/dist/esm/models/index.mjs +0 -1
- package/dist/esm/node/dataUrl.d.mts +0 -27
- package/dist/esm/node/dataUrl.mjs +0 -84
- package/dist/esm/node/file/FetchError.d.mts +0 -9
- package/dist/esm/node/file/FetchError.mjs +0 -16
- package/dist/esm/node/file/fetch.d.mts +0 -7
- package/dist/esm/node/file/fetch.mjs +0 -14
- package/dist/esm/node/file/fileReader.d.mts +0 -4
- package/dist/esm/node/file/fileReader.mjs +0 -62
- package/dist/esm/node/file/fileWriter.d.mts +0 -4
- package/dist/esm/node/file/fileWriter.mjs +0 -14
- package/dist/esm/node/file/index.d.mts +0 -4
- package/dist/esm/node/file/index.mjs +0 -3
- package/dist/esm/node/file/stat.d.mts +0 -5
- package/dist/esm/node/file/stat.mjs +0 -47
- package/dist/esm/node/file/util.d.mts +0 -9
- package/dist/esm/node/file/util.mjs +0 -57
- package/dist/esm/requests/RequestFsReadBinaryFile.d.mts +0 -11
- package/dist/esm/requests/RequestFsReadBinaryFile.mjs +0 -5
- package/dist/esm/requests/RequestFsReadFile.d.mts +0 -11
- package/dist/esm/requests/RequestFsReadFile.mjs +0 -3
- package/dist/esm/requests/RequestFsReadFileSync.d.mts +0 -11
- package/dist/esm/requests/RequestFsReadFileSync.mjs +0 -3
- package/dist/esm/requests/RequestFsStat.d.mts +0 -11
- package/dist/esm/requests/RequestFsStat.mjs +0 -5
- package/dist/esm/requests/RequestFsWriteFile.d.mts +0 -9
- package/dist/esm/requests/RequestFsWriteFile.mjs +0 -3
- package/dist/esm/requests/RequestZlibInflate.d.mts +0 -9
- package/dist/esm/requests/RequestZlibInflate.mjs +0 -3
- package/dist/esm/requests/index.d.mts +0 -7
- package/dist/esm/requests/index.mjs +0 -6
- package/dist/esm/test/test.helper.d.mts +0 -13
- package/dist/esm/test/test.helper.mjs +0 -37
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { isServiceResponseSuccess, ServiceBus } from '@cspell/cspell-service-bus';
|
|
2
|
-
import { compareStats } from './common/stat.mjs';
|
|
3
|
-
import { ErrorNotImplemented } from './errors/ErrorNotImplemented.mjs';
|
|
4
|
-
import { registerHandlers } from './handlers/node/file.mjs';
|
|
5
|
-
import { toURL, urlBasename, urlDirname } from './node/file/util.mjs';
|
|
6
|
-
import { RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, } from './requests/index.mjs';
|
|
7
|
-
let defaultCSpellIONode = undefined;
|
|
8
|
-
export class CSpellIONode {
|
|
9
|
-
constructor(serviceBus = new ServiceBus()) {
|
|
10
|
-
this.serviceBus = serviceBus;
|
|
11
|
-
registerHandlers(serviceBus);
|
|
12
|
-
}
|
|
13
|
-
readFile(uriOrFilename, encoding = 'utf8') {
|
|
14
|
-
const url = toURL(uriOrFilename);
|
|
15
|
-
const res = this.serviceBus.dispatch(RequestFsReadFile.create({ url, encoding }));
|
|
16
|
-
if (!isServiceResponseSuccess(res)) {
|
|
17
|
-
throw genError(res.error, 'readFile');
|
|
18
|
-
}
|
|
19
|
-
return res.value;
|
|
20
|
-
}
|
|
21
|
-
readFileSync(uriOrFilename, encoding = 'utf8') {
|
|
22
|
-
const url = toURL(uriOrFilename);
|
|
23
|
-
const res = this.serviceBus.dispatch(RequestFsReadFileSync.create({ url, encoding }));
|
|
24
|
-
if (!isServiceResponseSuccess(res)) {
|
|
25
|
-
throw genError(res.error, 'readFileSync');
|
|
26
|
-
}
|
|
27
|
-
return res.value;
|
|
28
|
-
}
|
|
29
|
-
writeFile(uriOrFilename, content) {
|
|
30
|
-
const url = toURL(uriOrFilename);
|
|
31
|
-
const res = this.serviceBus.dispatch(RequestFsWriteFile.create({ url, content }));
|
|
32
|
-
if (!isServiceResponseSuccess(res)) {
|
|
33
|
-
throw genError(res.error, 'writeFile');
|
|
34
|
-
}
|
|
35
|
-
return res.value;
|
|
36
|
-
}
|
|
37
|
-
getStat(uriOrFilename) {
|
|
38
|
-
const url = toURL(uriOrFilename);
|
|
39
|
-
const res = this.serviceBus.dispatch(RequestFsStat.create({ url }));
|
|
40
|
-
if (!isServiceResponseSuccess(res)) {
|
|
41
|
-
throw genError(res.error, 'getStat');
|
|
42
|
-
}
|
|
43
|
-
return res.value;
|
|
44
|
-
}
|
|
45
|
-
getStatSync(uriOrFilename) {
|
|
46
|
-
const url = toURL(uriOrFilename);
|
|
47
|
-
const res = this.serviceBus.dispatch(RequestFsStatSync.create({ url }));
|
|
48
|
-
if (!isServiceResponseSuccess(res)) {
|
|
49
|
-
throw genError(res.error, 'getStatSync');
|
|
50
|
-
}
|
|
51
|
-
return res.value;
|
|
52
|
-
}
|
|
53
|
-
compareStats(left, right) {
|
|
54
|
-
return compareStats(left, right);
|
|
55
|
-
}
|
|
56
|
-
toURL(uriOrFilename) {
|
|
57
|
-
return toURL(uriOrFilename);
|
|
58
|
-
}
|
|
59
|
-
uriBasename(uriOrFilename) {
|
|
60
|
-
return urlBasename(uriOrFilename);
|
|
61
|
-
}
|
|
62
|
-
uriDirname(uriOrFilename) {
|
|
63
|
-
return urlDirname(uriOrFilename);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function genError(err, alt) {
|
|
67
|
-
return err || new ErrorNotImplemented(alt);
|
|
68
|
-
}
|
|
69
|
-
export function getDefaultCSpellIO() {
|
|
70
|
-
if (defaultCSpellIONode)
|
|
71
|
-
return defaultCSpellIONode;
|
|
72
|
-
const cspellIO = new CSpellIONode();
|
|
73
|
-
defaultCSpellIONode = cspellIO;
|
|
74
|
-
return cspellIO;
|
|
75
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CSpellIO } from './CSpellIO.mjs';
|
|
2
|
-
import type { TextFileResource } from './models/FileResource.mjs';
|
|
3
|
-
import type { Stats } from './models/Stats.mjs';
|
|
4
|
-
export declare class CSpellIOWeb implements CSpellIO {
|
|
5
|
-
readFile(_uriOrFilename: string | URL): Promise<TextFileResource>;
|
|
6
|
-
readFileSync(_uriOrFilename: string | URL): TextFileResource;
|
|
7
|
-
writeFile(_uriOrFilename: string | URL, _content: string): Promise<void>;
|
|
8
|
-
getStat(_uriOrFilename: string | URL): Promise<Stats>;
|
|
9
|
-
getStatSync(_uriOrFilename: string | URL): Stats;
|
|
10
|
-
compareStats(left: Stats, right: Stats): number;
|
|
11
|
-
toURL(_uriOrFilename: string | URL): URL;
|
|
12
|
-
uriBasename(_uriOrFilename: string | URL): string;
|
|
13
|
-
uriDirname(_uriOrFilename: string | URL): URL;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=CSpellIOWeb.d.mts.map
|
package/dist/esm/CSpellIOWeb.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { compareStats } from './common/stat.mjs';
|
|
2
|
-
import { ErrorNotImplemented } from './errors/ErrorNotImplemented.mjs';
|
|
3
|
-
export class CSpellIOWeb {
|
|
4
|
-
readFile(_uriOrFilename) {
|
|
5
|
-
throw new ErrorNotImplemented('readFile');
|
|
6
|
-
}
|
|
7
|
-
readFileSync(_uriOrFilename) {
|
|
8
|
-
throw new ErrorNotImplemented('readFileSync');
|
|
9
|
-
}
|
|
10
|
-
writeFile(_uriOrFilename, _content) {
|
|
11
|
-
throw new ErrorNotImplemented('writeFile');
|
|
12
|
-
}
|
|
13
|
-
getStat(_uriOrFilename) {
|
|
14
|
-
throw new ErrorNotImplemented('getStat');
|
|
15
|
-
}
|
|
16
|
-
getStatSync(_uriOrFilename) {
|
|
17
|
-
throw new ErrorNotImplemented('getStatSync');
|
|
18
|
-
}
|
|
19
|
-
compareStats(left, right) {
|
|
20
|
-
return compareStats(left, right);
|
|
21
|
-
}
|
|
22
|
-
toURL(_uriOrFilename) {
|
|
23
|
-
throw new ErrorNotImplemented('toURL');
|
|
24
|
-
}
|
|
25
|
-
uriBasename(_uriOrFilename) {
|
|
26
|
-
throw new ErrorNotImplemented('uriBasename');
|
|
27
|
-
}
|
|
28
|
-
uriDirname(_uriOrFilename) {
|
|
29
|
-
throw new ErrorNotImplemented('uriDirname');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads an entire iterable and converts it into a promise.
|
|
3
|
-
* @param asyncIterable the async iterable to wait for.
|
|
4
|
-
*/
|
|
5
|
-
export declare function toArray<T>(asyncIterable: AsyncIterable<T> | Iterable<T> | Iterable<Promise<T>>): Promise<T[]>;
|
|
6
|
-
//# sourceMappingURL=asyncIterable.d.mts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads an entire iterable and converts it into a promise.
|
|
3
|
-
* @param asyncIterable the async iterable to wait for.
|
|
4
|
-
*/
|
|
5
|
-
export async function toArray(asyncIterable) {
|
|
6
|
-
const data = [];
|
|
7
|
-
for await (const item of asyncIterable) {
|
|
8
|
-
data.push(item);
|
|
9
|
-
}
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export declare function toUint8Array(data: ArrayBufferView): Uint8Array;
|
|
3
|
-
export declare function arrayBufferViewToBuffer(data: ArrayBufferView): Buffer;
|
|
4
|
-
/**
|
|
5
|
-
* Copy the data buffer.
|
|
6
|
-
* @param data - source data
|
|
7
|
-
* @returns A copy of the data
|
|
8
|
-
*/
|
|
9
|
-
export declare function copyArrayBufferView(data: ArrayBufferView): ArrayBufferView;
|
|
10
|
-
/**
|
|
11
|
-
* Slice an existing data view. Returns a new view using the same underlying data.
|
|
12
|
-
* @param data - data view
|
|
13
|
-
* @param byteOffset - offset from the beginning of the view.
|
|
14
|
-
* @param byteLength - optional length
|
|
15
|
-
*/
|
|
16
|
-
export declare function sliceView(data: ArrayBufferView, byteOffset: number, byteLength?: number): ArrayBufferView;
|
|
17
|
-
//# sourceMappingURL=arrayBuffers.d.mts.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export function toUint8Array(data) {
|
|
2
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
3
|
-
}
|
|
4
|
-
export function arrayBufferViewToBuffer(data) {
|
|
5
|
-
if (data instanceof Buffer) {
|
|
6
|
-
return data;
|
|
7
|
-
}
|
|
8
|
-
const buf = Buffer.from(data.buffer);
|
|
9
|
-
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
10
|
-
return buf;
|
|
11
|
-
}
|
|
12
|
-
return buf.subarray(data.byteOffset, data.byteOffset + data.byteLength);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Copy the data buffer.
|
|
16
|
-
* @param data - source data
|
|
17
|
-
* @returns A copy of the data
|
|
18
|
-
*/
|
|
19
|
-
export function copyArrayBufferView(data) {
|
|
20
|
-
return new Uint8Array(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength));
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Slice an existing data view. Returns a new view using the same underlying data.
|
|
24
|
-
* @param data - data view
|
|
25
|
-
* @param byteOffset - offset from the beginning of the view.
|
|
26
|
-
* @param byteLength - optional length
|
|
27
|
-
*/
|
|
28
|
-
export function sliceView(data, byteOffset, byteLength) {
|
|
29
|
-
const currentEnd = data.byteOffset + data.byteLength;
|
|
30
|
-
const start = Math.min(data.byteOffset + byteOffset, currentEnd);
|
|
31
|
-
const end = byteLength ? Math.min(currentEnd, start + byteLength) : currentEnd;
|
|
32
|
-
return {
|
|
33
|
-
buffer: data.buffer,
|
|
34
|
-
byteOffset: start,
|
|
35
|
-
byteLength: end - start,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { BufferEncodingExt } from './BufferEncoding.mjs';
|
|
2
|
-
export declare function decodeUtf16LE(data: ArrayBufferView): string;
|
|
3
|
-
export declare function decodeUtf16BE(buf: ArrayBufferView): string;
|
|
4
|
-
export declare function decode(data: ArrayBufferView, encoding?: BufferEncodingExt): string;
|
|
5
|
-
export declare function swapBytesInPlace(data: ArrayBufferView): ArrayBufferView;
|
|
6
|
-
export declare function swapBytes(data: ArrayBufferView): ArrayBufferView;
|
|
7
|
-
export declare function encodeString(str: string, encoding?: BufferEncodingExt, bom?: boolean): ArrayBufferView;
|
|
8
|
-
export declare function encodeUtf16LE(str: string, bom?: boolean): ArrayBufferView;
|
|
9
|
-
export declare function encodeUtf16BE(str: string, bom?: boolean): ArrayBufferView;
|
|
10
|
-
export declare function calcEncodingFromBom(data: ArrayBufferView): 'utf16be' | 'utf16le' | undefined;
|
|
11
|
-
//# sourceMappingURL=encode-decode.d.mts.map
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { arrayBufferViewToBuffer, copyArrayBufferView, toUint8Array } from './arrayBuffers.mjs';
|
|
2
|
-
const BOM_BE = 0xfeff;
|
|
3
|
-
const BOM_LE = 0xfffe;
|
|
4
|
-
export function decodeUtf16LE(data) {
|
|
5
|
-
let buf = arrayBufferViewToBuffer(data);
|
|
6
|
-
const bom = (buf[0] << 8) | buf[1];
|
|
7
|
-
buf = bom === BOM_LE ? buf.subarray(2) : buf;
|
|
8
|
-
return buf.toString('utf16le');
|
|
9
|
-
}
|
|
10
|
-
export function decodeUtf16BE(buf) {
|
|
11
|
-
return decodeUtf16LE(swapBytes(buf));
|
|
12
|
-
}
|
|
13
|
-
export function decode(data, encoding) {
|
|
14
|
-
const buf = arrayBufferViewToBuffer(data);
|
|
15
|
-
switch (encoding) {
|
|
16
|
-
case 'utf16be':
|
|
17
|
-
return decodeUtf16BE(buf);
|
|
18
|
-
case 'utf16le':
|
|
19
|
-
return decodeUtf16LE(buf);
|
|
20
|
-
}
|
|
21
|
-
if (buf.length < 2 || (encoding && !encoding.startsWith('utf')))
|
|
22
|
-
return buf.toString(encoding);
|
|
23
|
-
const bom = (buf[0] << 8) | buf[1];
|
|
24
|
-
if (bom === BOM_BE || (buf[0] === 0 && buf[1] !== 0))
|
|
25
|
-
return decodeUtf16BE(buf);
|
|
26
|
-
if (bom === BOM_LE || (buf[0] !== 0 && buf[1] === 0))
|
|
27
|
-
return decodeUtf16LE(buf);
|
|
28
|
-
return buf.toString(encoding);
|
|
29
|
-
}
|
|
30
|
-
export function swapBytesInPlace(data) {
|
|
31
|
-
const buf = arrayBufferViewToBuffer(data);
|
|
32
|
-
buf.swap16();
|
|
33
|
-
return buf;
|
|
34
|
-
}
|
|
35
|
-
export function swapBytes(data) {
|
|
36
|
-
const buf = copyArrayBufferView(data);
|
|
37
|
-
return swapBytesInPlace(buf);
|
|
38
|
-
}
|
|
39
|
-
export function encodeString(str, encoding, bom) {
|
|
40
|
-
switch (encoding) {
|
|
41
|
-
case 'utf16be':
|
|
42
|
-
return encodeUtf16BE(str, bom);
|
|
43
|
-
case 'utf16le':
|
|
44
|
-
return encodeUtf16LE(str, bom);
|
|
45
|
-
}
|
|
46
|
-
return Buffer.from(str, encoding);
|
|
47
|
-
}
|
|
48
|
-
export function encodeUtf16LE(str, bom = true) {
|
|
49
|
-
const buf = Buffer.from(str, 'utf16le');
|
|
50
|
-
if (bom) {
|
|
51
|
-
const target = Buffer.alloc(buf.length + 2);
|
|
52
|
-
target.writeUint16LE(BOM_BE);
|
|
53
|
-
buf.copy(target, 2);
|
|
54
|
-
return target;
|
|
55
|
-
}
|
|
56
|
-
return buf;
|
|
57
|
-
}
|
|
58
|
-
export function encodeUtf16BE(str, bom = true) {
|
|
59
|
-
return swapBytesInPlace(encodeUtf16LE(str, bom));
|
|
60
|
-
}
|
|
61
|
-
export function calcEncodingFromBom(data) {
|
|
62
|
-
const buf = toUint8Array(data);
|
|
63
|
-
if (buf.length < 2)
|
|
64
|
-
return undefined;
|
|
65
|
-
switch ((buf[0] << 8) | buf[1]) {
|
|
66
|
-
case BOM_BE:
|
|
67
|
-
return 'utf16be';
|
|
68
|
-
case BOM_LE:
|
|
69
|
-
return 'utf16le';
|
|
70
|
-
}
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Stats } from '../models/Stats.mjs';
|
|
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.mts.map
|
package/dist/esm/common/stat.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compare two Stats to see if they have the same value.
|
|
3
|
-
* @param left - Stats
|
|
4
|
-
* @param right - Stats
|
|
5
|
-
* @returns 0 - equal; 1 - left > right; -1 left < right
|
|
6
|
-
*/
|
|
7
|
-
export function compareStats(left, right) {
|
|
8
|
-
if (left === right)
|
|
9
|
-
return 0;
|
|
10
|
-
if (left.eTag || right.eTag)
|
|
11
|
-
return left.eTag === right.eTag ? 0 : (left.eTag || '') < (right.eTag || '') ? -1 : 1;
|
|
12
|
-
const diff = left.size - right.size || left.mtimeMs - right.mtimeMs;
|
|
13
|
-
return diff < 0 ? -1 : diff > 0 ? 1 : 0;
|
|
14
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { BufferEncodingExt } from './BufferEncoding.mjs';
|
|
2
|
-
export declare function createDecoderTransformer(encoding?: BufferEncodingExt): (iterable: AsyncIterable<string | ArrayBufferView> | Iterable<string | ArrayBufferView>) => AsyncIterable<string>;
|
|
3
|
-
export declare function encoderTransformer(iterable: Iterable<string>, encoding?: BufferEncodingExt): Iterable<ArrayBufferView>;
|
|
4
|
-
export declare function encoderTransformer(iterable: AsyncIterable<string>, encoding?: BufferEncodingExt): AsyncIterable<ArrayBufferView>;
|
|
5
|
-
export declare function encoderTransformer(iterable: Iterable<string> | AsyncIterable<string>, encoding?: BufferEncodingExt): Iterable<ArrayBufferView> | AsyncIterable<ArrayBufferView>;
|
|
6
|
-
//# sourceMappingURL=transformers.d.mts.map
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { sliceView } from './arrayBuffers.mjs';
|
|
2
|
-
import { calcEncodingFromBom, decode, decodeUtf16BE, decodeUtf16LE, encodeString } from './encode-decode.mjs';
|
|
3
|
-
export function createDecoderTransformer(encoding) {
|
|
4
|
-
function standardDecoder(buf) {
|
|
5
|
-
return decode(buf, encoding);
|
|
6
|
-
}
|
|
7
|
-
let decoder = undefined;
|
|
8
|
-
if (encoding && !encoding.startsWith('utf'))
|
|
9
|
-
return decoderNonUtf;
|
|
10
|
-
return decoderUtf;
|
|
11
|
-
async function* decoderNonUtf(iterable) {
|
|
12
|
-
for await (const buf of iterable) {
|
|
13
|
-
yield typeof buf === 'string' ? buf : decode(buf, encoding);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async function* decoderUtf(iterable) {
|
|
17
|
-
for await (const sb of iterable) {
|
|
18
|
-
if (typeof sb === 'string') {
|
|
19
|
-
yield sb;
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (sb.byteLength < 2) {
|
|
23
|
-
yield standardDecoder(sb);
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (decoder) {
|
|
27
|
-
yield decoder(sb);
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
decoder = standardDecoder;
|
|
31
|
-
const _encoding = calcEncodingFromBom(sb);
|
|
32
|
-
if (_encoding === 'utf16le') {
|
|
33
|
-
decoder = decodeUtf16LE;
|
|
34
|
-
yield decoder(sliceView(sb, 2));
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (_encoding === 'utf16be') {
|
|
38
|
-
decoder = decodeUtf16BE;
|
|
39
|
-
yield decoder(sliceView(sb, 2));
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
yield decoder(sb);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export function encoderTransformer(iterable, encoding) {
|
|
47
|
-
return isAsyncIterable(iterable) ? encoderAsyncIterable(iterable, encoding) : encoderIterable(iterable, encoding);
|
|
48
|
-
}
|
|
49
|
-
function* encoderIterable(iterable, encoding) {
|
|
50
|
-
let useBom = true;
|
|
51
|
-
for (const chunk of iterable) {
|
|
52
|
-
yield encodeString(chunk, encoding, useBom);
|
|
53
|
-
useBom = false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function* encoderAsyncIterable(iterable, encoding) {
|
|
57
|
-
let useBom = true;
|
|
58
|
-
for await (const chunk of iterable) {
|
|
59
|
-
yield encodeString(chunk, encoding, useBom);
|
|
60
|
-
useBom = false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function isAsyncIterable(v) {
|
|
64
|
-
return v && typeof v === 'object' && !!v[Symbol.asyncIterator];
|
|
65
|
-
}
|
package/dist/esm/file/file.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { getStat as GetStatFn, getStatSync as GetStatSyncFn, readFileText as ReadFileTextFn, readFileTextSync as ReadFileTextSyncFn } from '../node/file/index.mjs';
|
|
2
|
-
export declare const readFileText: typeof ReadFileTextFn;
|
|
3
|
-
export declare const readFileTextSync: typeof ReadFileTextSyncFn;
|
|
4
|
-
export declare const getStat: typeof GetStatFn;
|
|
5
|
-
export declare const getStatSync: typeof GetStatSyncFn;
|
|
6
|
-
//# sourceMappingURL=file.d.mts.map
|
package/dist/esm/file/file.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { getDefaultCSpellIO } from '../CSpellIONode.mjs';
|
|
2
|
-
import { toError } from '../errors/index.mjs';
|
|
3
|
-
export const readFileText = function (filename, encoding) {
|
|
4
|
-
return getDefaultCSpellIO()
|
|
5
|
-
.readFile(filename, encoding)
|
|
6
|
-
.then((fr) => fr.content);
|
|
7
|
-
};
|
|
8
|
-
export const readFileTextSync = function (filename, encoding) {
|
|
9
|
-
return getDefaultCSpellIO().readFileSync(filename, encoding).content;
|
|
10
|
-
};
|
|
11
|
-
export const getStat = function (filenameOrUri) {
|
|
12
|
-
return getDefaultCSpellIO().getStat(filenameOrUri).catch(toError);
|
|
13
|
-
};
|
|
14
|
-
export const getStatSync = function (filenameOrUri) {
|
|
15
|
-
try {
|
|
16
|
-
return getDefaultCSpellIO().getStatSync(filenameOrUri);
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
return toError(e);
|
|
20
|
-
}
|
|
21
|
-
};
|
package/dist/esm/file/index.mjs
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { createResponse, createResponseFail, isServiceResponseFailure, isServiceResponseSuccess, } from '@cspell/cspell-service-bus';
|
|
2
|
-
import assert from 'assert';
|
|
3
|
-
import { promises as fs, readFileSync, statSync } from 'fs';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import { gunzipSync, gzipSync } from 'zlib';
|
|
6
|
-
import { arrayBufferViewToBuffer } from '../../common/arrayBuffers.mjs';
|
|
7
|
-
import { decode } from '../../common/encode-decode.mjs';
|
|
8
|
-
import { toError } from '../../errors/index.mjs';
|
|
9
|
-
import { decodeDataUrl } from '../../node/dataUrl.mjs';
|
|
10
|
-
import { fetchURL } from '../../node/file/fetch.mjs';
|
|
11
|
-
import { getStatHttp } from '../../node/file/stat.mjs';
|
|
12
|
-
import { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync, RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, RequestZlibInflate, } from '../../requests/index.mjs';
|
|
13
|
-
const isGzFileRegExp = /\.gz($|[?#])/;
|
|
14
|
-
function isGzFile(url) {
|
|
15
|
-
return isGzFileRegExp.test(url.pathname);
|
|
16
|
-
}
|
|
17
|
-
/*
|
|
18
|
-
* NOTE: fileURLToPath is used because of yarn bug https://github.com/yarnpkg/berry/issues/899
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Handle Binary File Reads
|
|
22
|
-
*/
|
|
23
|
-
const handleRequestFsReadBinaryFile = RequestFsReadBinaryFile.createRequestHandler(({ params }) => createResponse(fs.readFile(fileURLToPath(params.url)).then((content) => ({ url: params.url, content }))), undefined, 'Node: Read Binary File.');
|
|
24
|
-
/**
|
|
25
|
-
* Handle Binary File Sync Reads
|
|
26
|
-
*/
|
|
27
|
-
const handleRequestFsReadBinaryFileSync = RequestFsReadBinaryFileSync.createRequestHandler(({ params }) => createResponse({ url: params.url, content: readFileSync(fileURLToPath(params.url)) }), undefined, 'Node: Sync Read Binary File.');
|
|
28
|
-
/**
|
|
29
|
-
* Handle UTF-8 Text File Reads
|
|
30
|
-
*/
|
|
31
|
-
const handleRequestFsReadFile = RequestFsReadFile.createRequestHandler((req, _, dispatcher) => {
|
|
32
|
-
const { url, encoding } = req.params;
|
|
33
|
-
const res = dispatcher.dispatch(RequestFsReadBinaryFile.create({ url }));
|
|
34
|
-
if (!isServiceResponseSuccess(res)) {
|
|
35
|
-
assert(isServiceResponseFailure(res));
|
|
36
|
-
return createResponseFail(req, res.error);
|
|
37
|
-
}
|
|
38
|
-
return createResponse(res.value.then((res) => {
|
|
39
|
-
const content = bufferToText(res.content, encoding);
|
|
40
|
-
return {
|
|
41
|
-
url,
|
|
42
|
-
baseFilename: res.baseFilename,
|
|
43
|
-
encoding,
|
|
44
|
-
...content,
|
|
45
|
-
};
|
|
46
|
-
}));
|
|
47
|
-
}, undefined, 'Node: Read Text File.');
|
|
48
|
-
/**
|
|
49
|
-
* Handle UTF-8 Text File Reads
|
|
50
|
-
*/
|
|
51
|
-
const handleRequestFsReadFileSync = RequestFsReadFileSync.createRequestHandler((req, _, dispatcher) => {
|
|
52
|
-
const { url, encoding } = req.params;
|
|
53
|
-
const res = dispatcher.dispatch(RequestFsReadBinaryFileSync.create({ url }));
|
|
54
|
-
if (!isServiceResponseSuccess(res)) {
|
|
55
|
-
assert(isServiceResponseFailure(res));
|
|
56
|
-
return createResponseFail(req, res.error);
|
|
57
|
-
}
|
|
58
|
-
return createResponse({
|
|
59
|
-
encoding,
|
|
60
|
-
...res.value,
|
|
61
|
-
...bufferToText(res.value.content, encoding),
|
|
62
|
-
});
|
|
63
|
-
}, undefined, 'Node: Sync Read Text File.');
|
|
64
|
-
/**
|
|
65
|
-
* Handle deflating gzip data
|
|
66
|
-
*/
|
|
67
|
-
const handleRequestZlibInflate = RequestZlibInflate.createRequestHandler(({ params }) => createResponse(gunzipSync(params.data).toString('utf-8')), undefined, 'Node: gz deflate.');
|
|
68
|
-
const supportedFetchProtocols = { 'http:': true, 'https:': true };
|
|
69
|
-
/**
|
|
70
|
-
* Handle fetching a file from http
|
|
71
|
-
*/
|
|
72
|
-
const handleRequestFsReadBinaryFileHttp = RequestFsReadBinaryFile.createRequestHandler((req, next) => {
|
|
73
|
-
const { url } = req.params;
|
|
74
|
-
if (!(url.protocol in supportedFetchProtocols))
|
|
75
|
-
return next(req);
|
|
76
|
-
return createResponse(fetchURL(url).then((content) => ({ url, content })));
|
|
77
|
-
}, undefined, 'Node: Read Http(s) file.');
|
|
78
|
-
/**
|
|
79
|
-
* Handle decoding a data url
|
|
80
|
-
*/
|
|
81
|
-
const handleRequestFsReadBinaryFileSyncData = RequestFsReadBinaryFileSync.createRequestHandler((req, next) => {
|
|
82
|
-
const { url } = req.params;
|
|
83
|
-
if (url.protocol !== 'data:')
|
|
84
|
-
return next(req);
|
|
85
|
-
const data = decodeDataUrl(url);
|
|
86
|
-
return createResponse({ url, content: data.data, baseFilename: data.attributes.get('filename') });
|
|
87
|
-
}, undefined, 'Node: Read data: urls.');
|
|
88
|
-
/**
|
|
89
|
-
* Handle decoding a data url
|
|
90
|
-
*/
|
|
91
|
-
const handleRequestFsReadBinaryFileData = RequestFsReadBinaryFile.createRequestHandler((req, next, dispatcher) => {
|
|
92
|
-
const { url } = req.params;
|
|
93
|
-
if (url.protocol !== 'data:')
|
|
94
|
-
return next(req);
|
|
95
|
-
const res = dispatcher.dispatch(RequestFsReadBinaryFileSync.create(req.params));
|
|
96
|
-
if (!isServiceResponseSuccess(res))
|
|
97
|
-
return res;
|
|
98
|
-
return createResponse(Promise.resolve(res.value));
|
|
99
|
-
}, undefined, 'Node: Read data: urls.');
|
|
100
|
-
function bufferToText(data, encoding) {
|
|
101
|
-
const buf = arrayBufferViewToBuffer(data);
|
|
102
|
-
const gz = buf[0] === 0x1f && buf[1] === 0x8b;
|
|
103
|
-
const content = gz ? decode(gunzipSync(buf), encoding) : decode(buf, encoding);
|
|
104
|
-
return { content, gz };
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Handle fs:stat
|
|
108
|
-
*/
|
|
109
|
-
const handleRequestFsStat = RequestFsStat.createRequestHandler(({ params }) => createResponse(fs.stat(fileURLToPath(params.url))), undefined, 'Node: fs.stat.');
|
|
110
|
-
/**
|
|
111
|
-
* Handle fs:statSync
|
|
112
|
-
*/
|
|
113
|
-
const handleRequestFsStatSync = RequestFsStatSync.createRequestHandler((req) => {
|
|
114
|
-
const { params } = req;
|
|
115
|
-
try {
|
|
116
|
-
return createResponse(statSync(fileURLToPath(params.url)));
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
return createResponseFail(req, toError(e));
|
|
120
|
-
}
|
|
121
|
-
}, undefined, 'Node: fs.stat.');
|
|
122
|
-
/**
|
|
123
|
-
* Handle deflating gzip data
|
|
124
|
-
*/
|
|
125
|
-
const handleRequestFsStatHttp = RequestFsStat.createRequestHandler((req, next) => {
|
|
126
|
-
const { url } = req.params;
|
|
127
|
-
if (!(url.protocol in supportedFetchProtocols))
|
|
128
|
-
return next(req);
|
|
129
|
-
return createResponse(getStatHttp(url));
|
|
130
|
-
}, undefined, 'Node: http get stat');
|
|
131
|
-
/**
|
|
132
|
-
* Handle fs:writeFile
|
|
133
|
-
*/
|
|
134
|
-
const handleRequestFsWriteFile = RequestFsWriteFile.createRequestHandler(({ params }) => createResponse(fs.writeFile(params.url, params.content)), undefined, 'Node: fs.writeFile');
|
|
135
|
-
/**
|
|
136
|
-
* Handle fs:writeFile compressed
|
|
137
|
-
*/
|
|
138
|
-
const handleRequestFsWriteFileGz = RequestFsWriteFile.createRequestHandler((req, next) => {
|
|
139
|
-
const { url, content } = req.params;
|
|
140
|
-
if (!isGzFile(url))
|
|
141
|
-
return next(req);
|
|
142
|
-
return createResponse(fs.writeFile(url, gzipSync(content)));
|
|
143
|
-
}, undefined, 'Node: http get stat');
|
|
144
|
-
export function registerHandlers(serviceBus) {
|
|
145
|
-
/**
|
|
146
|
-
* Handlers are in order of low to high level
|
|
147
|
-
* Order is VERY important.
|
|
148
|
-
*/
|
|
149
|
-
const handlers = [
|
|
150
|
-
handleRequestFsWriteFile,
|
|
151
|
-
handleRequestFsWriteFileGz,
|
|
152
|
-
handleRequestFsReadBinaryFile,
|
|
153
|
-
handleRequestFsReadBinaryFileSync,
|
|
154
|
-
handleRequestFsReadBinaryFileHttp,
|
|
155
|
-
handleRequestFsReadBinaryFileData,
|
|
156
|
-
handleRequestFsReadBinaryFileSyncData,
|
|
157
|
-
handleRequestFsReadFile,
|
|
158
|
-
handleRequestFsReadFileSync,
|
|
159
|
-
handleRequestZlibInflate,
|
|
160
|
-
handleRequestFsStatSync,
|
|
161
|
-
handleRequestFsStat,
|
|
162
|
-
handleRequestFsStatHttp,
|
|
163
|
-
];
|
|
164
|
-
handlers.forEach((handler) => serviceBus.addHandler(handler));
|
|
165
|
-
}
|
package/dist/esm/index.d.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { toArray as asyncIterableToArray } from './async/asyncIterable.mjs';
|
|
2
|
-
export type { CSpellIO } from './CSpellIO.mjs';
|
|
3
|
-
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.mjs';
|
|
4
|
-
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.mjs';
|
|
5
|
-
export type { Stats } from './models/Stats.mjs';
|
|
6
|
-
export { encodeDataUrl, toDataUrl } from './node/dataUrl.mjs';
|
|
7
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { toArray as asyncIterableToArray } from './async/asyncIterable.mjs';
|
|
2
|
-
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.mjs';
|
|
3
|
-
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.mjs';
|
|
4
|
-
export { encodeDataUrl, toDataUrl } from './node/dataUrl.mjs';
|