Socket
Socket
Sign inDemoInstall

cspell-io

Package Overview
Dependencies
Maintainers
1
Versions
269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cspell-io - npm Package Compare versions

Comparing version 7.0.0-alpha.2 to 7.0.0

dist/cjs/common/arrayBuffers.d.ts

19

dist/cjs/common/encode-decode.d.ts

@@ -1,12 +0,11 @@

/// <reference types="node" />
import type { BufferEncodingExt } from './BufferEncoding.js';
export declare function decodeUtf16LE(buf: Buffer): string;
export declare function decodeUtf16BE(buf: Buffer): string;
export declare function decode(buf: Buffer, encoding?: BufferEncodingExt): string;
export declare function swapBytesInPlace(buf: Buffer): Buffer;
export declare function swapBytes(buf: Buffer): Buffer;
export declare function encodeString(str: string, encoding?: BufferEncodingExt, bom?: boolean): Buffer;
export declare function encodeUtf16LE(str: string, bom?: boolean): Buffer;
export declare function encodeUtf16BE(str: string, bom?: boolean): Buffer;
export declare function calcEncodingFromBom(buf: Buffer): 'utf16be' | 'utf16le' | undefined;
export declare function decodeUtf16LE(data: ArrayBufferView): string;
export declare function decodeUtf16BE(buf: ArrayBufferView): string;
export declare function decode(data: ArrayBufferView, encoding?: BufferEncodingExt): string;
export declare function swapBytesInPlace(data: ArrayBufferView): ArrayBufferView;
export declare function swapBytes(data: ArrayBufferView): ArrayBufferView;
export declare function encodeString(str: string, encoding?: BufferEncodingExt, bom?: boolean): ArrayBufferView;
export declare function encodeUtf16LE(str: string, bom?: boolean): ArrayBufferView;
export declare function encodeUtf16BE(str: string, bom?: boolean): ArrayBufferView;
export declare function calcEncodingFromBom(data: ArrayBufferView): 'utf16be' | 'utf16le' | undefined;
//# sourceMappingURL=encode-decode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calcEncodingFromBom = exports.encodeUtf16BE = exports.encodeUtf16LE = exports.encodeString = exports.swapBytes = exports.swapBytesInPlace = exports.decode = exports.decodeUtf16BE = exports.decodeUtf16LE = void 0;
const arrayBuffers_js_1 = require("./arrayBuffers.js");
const BOM_BE = 0xfeff;
const BOM_LE = 0xfffe;
function decodeUtf16LE(buf) {
function decodeUtf16LE(data) {
let buf = (0, arrayBuffers_js_1.arrayBufferViewToBuffer)(data);
const bom = (buf[0] << 8) | buf[1];

@@ -16,3 +18,4 @@ buf = bom === BOM_LE ? buf.subarray(2) : buf;

exports.decodeUtf16BE = decodeUtf16BE;
function decode(buf, encoding) {
function decode(data, encoding) {
const buf = (0, arrayBuffers_js_1.arrayBufferViewToBuffer)(data);
switch (encoding) {

@@ -34,14 +37,11 @@ case 'utf16be':

exports.decode = decode;
function swapBytesInPlace(buf) {
for (let i = 0; i < buf.length - 1; i += 2) {
const v = buf[i];
buf[i] = buf[i + 1];
buf[i + 1] = v;
}
function swapBytesInPlace(data) {
const buf = (0, arrayBuffers_js_1.arrayBufferViewToBuffer)(data);
buf.swap16();
return buf;
}
exports.swapBytesInPlace = swapBytesInPlace;
function swapBytes(buf) {
const tBuf = Buffer.from(buf);
return swapBytesInPlace(tBuf);
function swapBytes(data) {
const buf = (0, arrayBuffers_js_1.copyArrayBufferView)(data);
return swapBytesInPlace(buf);
}

@@ -74,3 +74,4 @@ exports.swapBytes = swapBytes;

exports.encodeUtf16BE = encodeUtf16BE;
function calcEncodingFromBom(buf) {
function calcEncodingFromBom(data) {
const buf = (0, arrayBuffers_js_1.toUint8Array)(data);
if (buf.length < 2)

@@ -77,0 +78,0 @@ return undefined;

@@ -1,7 +0,6 @@

/// <reference types="node" />
import type { BufferEncodingExt } from './BufferEncoding.js';
export declare function createDecoderTransformer(encoding?: BufferEncodingExt): (iterable: AsyncIterable<string | Buffer> | Iterable<string | Buffer>) => AsyncIterable<string>;
export declare function encoderTransformer(iterable: Iterable<string>, encoding?: BufferEncodingExt): Iterable<Buffer>;
export declare function encoderTransformer(iterable: AsyncIterable<string>, encoding?: BufferEncodingExt): AsyncIterable<Buffer>;
export declare function encoderTransformer(iterable: Iterable<string> | AsyncIterable<string>, encoding?: BufferEncodingExt): Iterable<Buffer> | AsyncIterable<Buffer>;
export declare function createDecoderTransformer(encoding?: BufferEncodingExt): (iterable: AsyncIterable<string | ArrayBufferView> | Iterable<string | ArrayBufferView>) => AsyncIterable<string>;
export declare function encoderTransformer(iterable: Iterable<string>, encoding?: BufferEncodingExt): Iterable<ArrayBufferView>;
export declare function encoderTransformer(iterable: AsyncIterable<string>, encoding?: BufferEncodingExt): AsyncIterable<ArrayBufferView>;
export declare function encoderTransformer(iterable: Iterable<string> | AsyncIterable<string>, encoding?: BufferEncodingExt): Iterable<ArrayBufferView> | AsyncIterable<ArrayBufferView>;
//# sourceMappingURL=transformers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encoderTransformer = exports.createDecoderTransformer = void 0;
const arrayBuffers_js_1 = require("./arrayBuffers.js");
const encode_decode_js_1 = require("./encode-decode.js");

@@ -24,3 +25,3 @@ function createDecoderTransformer(encoding) {

}
if (sb.length < 2) {
if (sb.byteLength < 2) {
yield standardDecoder(sb);

@@ -37,3 +38,3 @@ continue;

decoder = encode_decode_js_1.decodeUtf16LE;
yield decoder(sb.subarray(2));
yield decoder((0, arrayBuffers_js_1.sliceView)(sb, 2));
continue;

@@ -43,3 +44,3 @@ }

decoder = encode_decode_js_1.decodeUtf16BE;
yield decoder(sb.subarray(2));
yield decoder((0, arrayBuffers_js_1.sliceView)(sb, 2));
continue;

@@ -46,0 +47,0 @@ }

@@ -1,4 +0,4 @@

/// <reference types="node" />
import { ServiceBus } from '@cspell/cspell-service-bus';
import type { CSpellIO } from './CSpellIO.js';
import type { BufferEncoding } from './models/BufferEncoding.js';
import type { TextFileResource } from './models/FileResource.js';

@@ -5,0 +5,0 @@ import type { Stats } from './models/Stats.js';

@@ -1,6 +0,6 @@

import type { getStat as GetStatFn, getStatSync as GetStatSyncFn, readFile as ReadFileFn, readFileSync as ReadFileSyncFn } from '../node/file/index.js';
export declare const readFile: typeof ReadFileFn;
export declare const readFileSync: typeof ReadFileSyncFn;
import type { getStat as GetStatFn, getStatSync as GetStatSyncFn, readFileText as ReadFileTextFn, readFileTextSync as ReadFileTextSyncFn } from '../node/file/index.js';
export declare const readFileText: typeof ReadFileTextFn;
export declare const readFileTextSync: typeof ReadFileTextSyncFn;
export declare const getStat: typeof GetStatFn;
export declare const getStatSync: typeof GetStatSyncFn;
//# sourceMappingURL=file.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStatSync = exports.getStat = exports.readFileSync = exports.readFile = void 0;
exports.getStatSync = exports.getStat = exports.readFileTextSync = exports.readFileText = void 0;
const CSpellIONode_js_1 = require("../CSpellIONode.js");
const index_js_1 = require("../errors/index.js");
const readFile = function (filename, encoding) {
const readFileText = function (filename, encoding) {
return (0, CSpellIONode_js_1.getDefaultCSpellIO)()

@@ -11,7 +11,7 @@ .readFile(filename, encoding)

};
exports.readFile = readFile;
const readFileSync = function (filename, encoding) {
exports.readFileText = readFileText;
const readFileTextSync = function (filename, encoding) {
return (0, CSpellIONode_js_1.getDefaultCSpellIO)().readFileSync(filename, encoding).content;
};
exports.readFileSync = readFileSync;
exports.readFileTextSync = readFileTextSync;
const getStat = function (filenameOrUri) {

@@ -18,0 +18,0 @@ return (0, CSpellIONode_js_1.getDefaultCSpellIO)().getStat(filenameOrUri).catch(index_js_1.toError);

export { writeToFile, writeToFileIterable, writeToFileIterable as writeToFileIterableP } from './../node/file/index.js';
export { getStat, getStatSync, readFile, readFileSync } from './file.js';
export { getStat, getStatSync, readFileText, readFileTextSync } from './file.js';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readFileSync = exports.readFile = exports.getStatSync = exports.getStat = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = void 0;
exports.readFileTextSync = exports.readFileText = exports.getStatSync = exports.getStat = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = void 0;
var index_js_1 = require("./../node/file/index.js");

@@ -11,4 +11,4 @@ Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return index_js_1.writeToFile; } });

Object.defineProperty(exports, "getStatSync", { enumerable: true, get: function () { return file_js_1.getStatSync; } });
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return file_js_1.readFile; } });
Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return file_js_1.readFileSync; } });
Object.defineProperty(exports, "readFileText", { enumerable: true, get: function () { return file_js_1.readFileText; } });
Object.defineProperty(exports, "readFileTextSync", { enumerable: true, get: function () { return file_js_1.readFileTextSync; } });
//# sourceMappingURL=index.js.map

@@ -12,2 +12,3 @@ "use strict";

const zlib_1 = require("zlib");
const arrayBuffers_js_1 = require("../../common/arrayBuffers.js");
const encode_decode_js_1 = require("../../common/encode-decode.js");

@@ -44,7 +45,11 @@ const index_js_1 = require("../../errors/index.js");

}
return (0, cspell_service_bus_1.createResponse)(res.value.then((res) => ({
url,
content: bufferToText(res.content, encoding),
baseFilename: res.baseFilename,
})));
return (0, cspell_service_bus_1.createResponse)(res.value.then((res) => {
const content = bufferToText(res.content, encoding);
return {
url,
baseFilename: res.baseFilename,
encoding,
...content,
};
}));
}, undefined, 'Node: Read Text File.');

@@ -62,4 +67,5 @@ /**

return (0, cspell_service_bus_1.createResponse)({
encoding,
...res.value,
content: bufferToText(res.value.content, encoding),
...bufferToText(res.value.content, encoding),
});

@@ -103,4 +109,7 @@ }, undefined, 'Node: Sync Read Text File.');

}, undefined, 'Node: Read data: urls.');
function bufferToText(buf, encoding) {
return buf[0] === 0x1f && buf[1] === 0x8b ? (0, encode_decode_js_1.decode)((0, zlib_1.gunzipSync)(buf), encoding) : (0, encode_decode_js_1.decode)(buf, encoding);
function bufferToText(data, encoding) {
const buf = (0, arrayBuffers_js_1.arrayBufferViewToBuffer)(data);
const gz = buf[0] === 0x1f && buf[1] === 0x8b;
const content = gz ? (0, encode_decode_js_1.decode)((0, zlib_1.gunzipSync)(buf), encoding) : (0, encode_decode_js_1.decode)(buf, encoding);
return { content, gz };
}

@@ -107,0 +116,0 @@ /**

export { toArray as asyncIterableToArray } from './async/asyncIterable.js';
export type { CSpellIO } from './CSpellIO.js';
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js';
export { getStat, getStatSync, readFile, readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
export type { Stats } from './models/Stats.js';
export { encodeDataUrl, toDataUrl } from './node/dataUrl.js';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toDataUrl = exports.encodeDataUrl = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = exports.readFileSync = exports.readFile = exports.getStatSync = exports.getStat = exports.getDefaultCSpellIO = exports.CSpellIONode = exports.asyncIterableToArray = void 0;
exports.toDataUrl = exports.encodeDataUrl = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = exports.readFileTextSync = exports.readFileText = exports.getStatSync = exports.getStat = exports.getDefaultCSpellIO = exports.CSpellIONode = exports.asyncIterableToArray = void 0;
var asyncIterable_js_1 = require("./async/asyncIterable.js");

@@ -12,4 +12,4 @@ Object.defineProperty(exports, "asyncIterableToArray", { enumerable: true, get: function () { return asyncIterable_js_1.toArray; } });

Object.defineProperty(exports, "getStatSync", { enumerable: true, get: function () { return index_js_1.getStatSync; } });
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return index_js_1.readFile; } });
Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return index_js_1.readFileSync; } });
Object.defineProperty(exports, "readFileText", { enumerable: true, get: function () { return index_js_1.readFileText; } });
Object.defineProperty(exports, "readFileTextSync", { enumerable: true, get: function () { return index_js_1.readFileTextSync; } });
Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return index_js_1.writeToFile; } });

@@ -16,0 +16,0 @@ Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return index_js_1.writeToFileIterable; } });

@@ -1,2 +0,2 @@

export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'binary' | 'latin1' | 'hex';
export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'utf16be' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'binary' | 'latin1' | 'hex';
//# sourceMappingURL=BufferEncoding.d.ts.map

@@ -1,3 +0,3 @@

/// <reference types="node" />
export interface FileResource {
import type { BufferEncoding } from './BufferEncoding.js';
export interface FileReference {
/**

@@ -7,6 +7,8 @@ * The URL of the File

url: URL;
}
export interface FileResource extends FileReference {
/**
* The contents of the file
*/
content: string | Buffer;
content: string | ArrayBufferView;
/**

@@ -17,9 +19,19 @@ * The filename of the file if known.

baseFilename?: string | undefined;
/**
* - `true` if the content had been gzip compressed.
* - `false` if the content was NOT gzip compressed.
* - `undefined` if it is unknown
*/
gz?: boolean;
}
export interface TextFileResource extends FileResource {
content: string;
/**
* The encoding used to decode the file.
*/
encoding: BufferEncoding;
}
export interface BinaryFileResource extends FileResource {
content: Buffer;
content: ArrayBufferView;
}
//# sourceMappingURL=FileResource.d.ts.map
import type { BufferEncoding } from '../../models/BufferEncoding.js';
export declare function readFile(filename: string | URL, encoding?: BufferEncoding): Promise<string>;
export declare function readFileSync(filename: string, encoding?: BufferEncoding): string;
export declare function readFileText(filename: string | URL, encoding?: BufferEncoding): Promise<string>;
export declare function readFileTextSync(filename: string, encoding?: BufferEncoding): string;
//# sourceMappingURL=fileReader.d.ts.map

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.readFileSync = exports.readFile = void 0;
exports.readFileTextSync = exports.readFileText = void 0;
// cSpell:ignore curr

@@ -42,3 +42,3 @@ // cSpell:words zlib iconv

const pipeline = (0, util_1.promisify)(Stream.pipeline);
async function readFile(filename, encoding) {
async function readFileText(filename, encoding) {
const url = (0, util_js_1.toURL)(filename);

@@ -48,11 +48,11 @@ if (!(0, util_js_1.isSupportedURL)(url)) {

}
return (0, util_js_1.isFileURL)(url) ? _readFile(url, encoding) : _fetchURL(url, encoding);
return (0, util_js_1.isFileURL)(url) ? _readFileText(url, encoding) : _fetchTextFromURL(url, encoding);
}
exports.readFile = readFile;
function _readFile(url, encoding) {
exports.readFileText = readFileText;
function _readFileText(url, encoding) {
// Convert it to a string because Yarn2 cannot handle URLs.
const filename = (0, url_1.fileURLToPath)(url);
return _read(() => fs.createReadStream(filename), (0, util_js_1.isZipped)(filename), encoding);
return _readText(() => fs.createReadStream(filename), (0, util_js_1.isZipped)(filename), encoding);
}
async function _fetchURL(url, encoding) {
async function _fetchTextFromURL(url, encoding) {
const response = await (0, fetch_js_1.fetch)(url);

@@ -62,21 +62,29 @@ if (!response.ok) {

}
return _read(() => response.body, (0, util_js_1.isZipped)(url), encoding);
return _readText(() => response.body, (0, util_js_1.isZipped)(url), encoding);
}
async function _read(getStream, isZipped, encoding) {
async function _readText(getStream, isZipped, encoding) {
const stream = getStream();
const decoder = (0, transformers_js_1.createDecoderTransformer)(encoding);
const collector = createCollector(encoding || defaultEncoding);
const collector = createTextCollector(encoding || defaultEncoding);
return isZipped ? pipeline(stream, zlib.createGunzip(), decoder, collector) : pipeline(stream, decoder, collector);
}
function readFileSync(filename, encoding) {
function readFileTextSync(filename, encoding) {
const rawData = fs.readFileSync(filename);
const data = (0, util_js_1.isZipped)(filename) ? zlib.gunzipSync(rawData) : rawData;
return !encoding || encoding.startsWith('utf') ? (0, encode_decode_js_1.decode)(data) : data.toString(encoding);
return !encoding || encoding.startsWith('utf')
? (0, encode_decode_js_1.decode)(data)
: encoding === 'utf16be'
? data.swap16().toString('utf16le')
: data.toString(encoding);
}
exports.readFileSync = readFileSync;
function createCollector(encoding) {
exports.readFileTextSync = readFileTextSync;
function createTextCollector(encoding) {
async function collect(iterable) {
const buf = [];
for await (const sb of iterable) {
buf.push(typeof sb === 'string' ? sb : sb.toString(encoding));
buf.push(typeof sb === 'string'
? sb
: encoding === 'utf16be'
? sb.swap16().toString('utf16le')
: sb.toString(encoding));
}

@@ -83,0 +91,0 @@ return buf.join('');

@@ -1,4 +0,4 @@

export { readFile, readFileSync } from './fileReader.js';
export { readFileText, readFileTextSync } from './fileReader.js';
export { writeToFile, writeToFileIterable } from './fileWriter.js';
export { getStat, getStatSync } from './stat.js';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStatSync = exports.getStat = exports.writeToFileIterable = exports.writeToFile = exports.readFileSync = exports.readFile = void 0;
exports.getStatSync = exports.getStat = exports.writeToFileIterable = exports.writeToFile = exports.readFileTextSync = exports.readFileText = void 0;
var fileReader_js_1 = require("./fileReader.js");
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return fileReader_js_1.readFile; } });
Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return fileReader_js_1.readFileSync; } });
Object.defineProperty(exports, "readFileText", { enumerable: true, get: function () { return fileReader_js_1.readFileText; } });
Object.defineProperty(exports, "readFileTextSync", { enumerable: true, get: function () { return fileReader_js_1.readFileTextSync; } });
var fileWriter_js_1 = require("./fileWriter.js");

@@ -8,0 +8,0 @@ Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return fileWriter_js_1.writeToFile; } });

export { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync } from './RequestFsReadBinaryFile.js';
export { RequestFsReadFile } from './RequestFsReadFile.js';
export { RequestFsReadFileSync } from './RequestFsReadFileSync.js';
export { RequestFsReadFileText as RequestFsReadFile } from './RequestFsReadFile.js';
export { RequestFsReadFileTextSync as RequestFsReadFileSync } from './RequestFsReadFileSync.js';
export { RequestFsStat, RequestFsStatSync } from './RequestFsStat.js';

@@ -5,0 +5,0 @@ export { RequestFsWriteFile } from './RequestFsWriteFile.js';

@@ -8,5 +8,5 @@ "use strict";

var RequestFsReadFile_js_1 = require("./RequestFsReadFile.js");
Object.defineProperty(exports, "RequestFsReadFile", { enumerable: true, get: function () { return RequestFsReadFile_js_1.RequestFsReadFile; } });
Object.defineProperty(exports, "RequestFsReadFile", { enumerable: true, get: function () { return RequestFsReadFile_js_1.RequestFsReadFileText; } });
var RequestFsReadFileSync_js_1 = require("./RequestFsReadFileSync.js");
Object.defineProperty(exports, "RequestFsReadFileSync", { enumerable: true, get: function () { return RequestFsReadFileSync_js_1.RequestFsReadFileSync; } });
Object.defineProperty(exports, "RequestFsReadFileSync", { enumerable: true, get: function () { return RequestFsReadFileSync_js_1.RequestFsReadFileTextSync; } });
var RequestFsStat_js_1 = require("./RequestFsStat.js");

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "RequestFsStat", { enumerable: true, get: function () { return RequestFsStat_js_1.RequestFsStat; } });

@@ -1,3 +0,3 @@

/// <reference types="node" />
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus';
import type { BufferEncoding } from '../models/BufferEncoding';
import type { TextFileResource } from '../models/FileResource.js';

@@ -8,5 +8,5 @@ interface RequestParams {

}
export declare const RequestFsReadFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<TextFileResource>>, RequestParams, "fs:readFile">;
export type RequestFsReadFile = ServiceRequestFactoryRequestType<typeof RequestFsReadFile>;
export declare const RequestFsReadFileText: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<TextFileResource>>, RequestParams, "fs:readFile">;
export type RequestFsReadFileText = ServiceRequestFactoryRequestType<typeof RequestFsReadFileText>;
export {};
//# sourceMappingURL=RequestFsReadFile.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RequestFsReadFile = void 0;
exports.RequestFsReadFileText = void 0;
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
const RequestType = 'fs:readFile';
exports.RequestFsReadFile = (0, cspell_service_bus_1.requestFactory)(RequestType);
exports.RequestFsReadFileText = (0, cspell_service_bus_1.requestFactory)(RequestType);
//# sourceMappingURL=RequestFsReadFile.js.map

@@ -1,3 +0,3 @@

/// <reference types="node" />
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus';
import type { BufferEncoding } from '../models/BufferEncoding';
import type { TextFileResource } from '../models/FileResource.js';

@@ -8,5 +8,5 @@ interface RequestParams {

}
export declare const RequestFsReadFileSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, TextFileResource>, RequestParams, "fs:readFileSync">;
export type RequestFsReadFileSync = ServiceRequestFactoryRequestType<typeof RequestFsReadFileSync>;
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, TextFileResource>, RequestParams, "fs:readFileSync">;
export type RequestFsReadFileTextSync = ServiceRequestFactoryRequestType<typeof RequestFsReadFileTextSync>;
export {};
//# sourceMappingURL=RequestFsReadFileSync.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RequestFsReadFileSync = void 0;
exports.RequestFsReadFileTextSync = void 0;
const cspell_service_bus_1 = require("@cspell/cspell-service-bus");
const RequestType = 'fs:readFileSync';
exports.RequestFsReadFileSync = (0, cspell_service_bus_1.requestFactory)(RequestType);
exports.RequestFsReadFileTextSync = (0, cspell_service_bus_1.requestFactory)(RequestType);
//# sourceMappingURL=RequestFsReadFileSync.js.map

@@ -1,12 +0,11 @@

/// <reference types="node" />
import type { BufferEncodingExt } from './BufferEncoding.js';
export declare function decodeUtf16LE(buf: Buffer): string;
export declare function decodeUtf16BE(buf: Buffer): string;
export declare function decode(buf: Buffer, encoding?: BufferEncodingExt): string;
export declare function swapBytesInPlace(buf: Buffer): Buffer;
export declare function swapBytes(buf: Buffer): Buffer;
export declare function encodeString(str: string, encoding?: BufferEncodingExt, bom?: boolean): Buffer;
export declare function encodeUtf16LE(str: string, bom?: boolean): Buffer;
export declare function encodeUtf16BE(str: string, bom?: boolean): Buffer;
export declare function calcEncodingFromBom(buf: Buffer): 'utf16be' | 'utf16le' | undefined;
export declare function decodeUtf16LE(data: ArrayBufferView): string;
export declare function decodeUtf16BE(buf: ArrayBufferView): string;
export declare function decode(data: ArrayBufferView, encoding?: BufferEncodingExt): string;
export declare function swapBytesInPlace(data: ArrayBufferView): ArrayBufferView;
export declare function swapBytes(data: ArrayBufferView): ArrayBufferView;
export declare function encodeString(str: string, encoding?: BufferEncodingExt, bom?: boolean): ArrayBufferView;
export declare function encodeUtf16LE(str: string, bom?: boolean): ArrayBufferView;
export declare function encodeUtf16BE(str: string, bom?: boolean): ArrayBufferView;
export declare function calcEncodingFromBom(data: ArrayBufferView): 'utf16be' | 'utf16le' | undefined;
//# sourceMappingURL=encode-decode.d.ts.map

@@ -0,4 +1,6 @@

import { arrayBufferViewToBuffer, copyArrayBufferView, toUint8Array } from './arrayBuffers.js';
const BOM_BE = 0xfeff;
const BOM_LE = 0xfffe;
export function decodeUtf16LE(buf) {
export function decodeUtf16LE(data) {
let buf = arrayBufferViewToBuffer(data);
const bom = (buf[0] << 8) | buf[1];

@@ -11,3 +13,4 @@ buf = bom === BOM_LE ? buf.subarray(2) : buf;

}
export function decode(buf, encoding) {
export function decode(data, encoding) {
const buf = arrayBufferViewToBuffer(data);
switch (encoding) {

@@ -28,13 +31,10 @@ case 'utf16be':

}
export function swapBytesInPlace(buf) {
for (let i = 0; i < buf.length - 1; i += 2) {
const v = buf[i];
buf[i] = buf[i + 1];
buf[i + 1] = v;
}
export function swapBytesInPlace(data) {
const buf = arrayBufferViewToBuffer(data);
buf.swap16();
return buf;
}
export function swapBytes(buf) {
const tBuf = Buffer.from(buf);
return swapBytesInPlace(tBuf);
export function swapBytes(data) {
const buf = copyArrayBufferView(data);
return swapBytesInPlace(buf);
}

@@ -63,3 +63,4 @@ export function encodeString(str, encoding, bom) {

}
export function calcEncodingFromBom(buf) {
export function calcEncodingFromBom(data) {
const buf = toUint8Array(data);
if (buf.length < 2)

@@ -66,0 +67,0 @@ return undefined;

@@ -1,7 +0,6 @@

/// <reference types="node" />
import type { BufferEncodingExt } from './BufferEncoding.js';
export declare function createDecoderTransformer(encoding?: BufferEncodingExt): (iterable: AsyncIterable<string | Buffer> | Iterable<string | Buffer>) => AsyncIterable<string>;
export declare function encoderTransformer(iterable: Iterable<string>, encoding?: BufferEncodingExt): Iterable<Buffer>;
export declare function encoderTransformer(iterable: AsyncIterable<string>, encoding?: BufferEncodingExt): AsyncIterable<Buffer>;
export declare function encoderTransformer(iterable: Iterable<string> | AsyncIterable<string>, encoding?: BufferEncodingExt): Iterable<Buffer> | AsyncIterable<Buffer>;
export declare function createDecoderTransformer(encoding?: BufferEncodingExt): (iterable: AsyncIterable<string | ArrayBufferView> | Iterable<string | ArrayBufferView>) => AsyncIterable<string>;
export declare function encoderTransformer(iterable: Iterable<string>, encoding?: BufferEncodingExt): Iterable<ArrayBufferView>;
export declare function encoderTransformer(iterable: AsyncIterable<string>, encoding?: BufferEncodingExt): AsyncIterable<ArrayBufferView>;
export declare function encoderTransformer(iterable: Iterable<string> | AsyncIterable<string>, encoding?: BufferEncodingExt): Iterable<ArrayBufferView> | AsyncIterable<ArrayBufferView>;
//# sourceMappingURL=transformers.d.ts.map

@@ -0,1 +1,2 @@

import { sliceView } from './arrayBuffers.js';
import { calcEncodingFromBom, decode, decodeUtf16BE, decodeUtf16LE, encodeString } from './encode-decode.js';

@@ -21,3 +22,3 @@ export function createDecoderTransformer(encoding) {

}
if (sb.length < 2) {
if (sb.byteLength < 2) {
yield standardDecoder(sb);

@@ -34,3 +35,3 @@ continue;

decoder = decodeUtf16LE;
yield decoder(sb.subarray(2));
yield decoder(sliceView(sb, 2));
continue;

@@ -40,3 +41,3 @@ }

decoder = decodeUtf16BE;
yield decoder(sb.subarray(2));
yield decoder(sliceView(sb, 2));
continue;

@@ -43,0 +44,0 @@ }

@@ -1,4 +0,4 @@

/// <reference types="node" />
import { ServiceBus } from '@cspell/cspell-service-bus';
import type { CSpellIO } from './CSpellIO.js';
import type { BufferEncoding } from './models/BufferEncoding.js';
import type { TextFileResource } from './models/FileResource.js';

@@ -5,0 +5,0 @@ import type { Stats } from './models/Stats.js';

@@ -1,6 +0,6 @@

import type { getStat as GetStatFn, getStatSync as GetStatSyncFn, readFile as ReadFileFn, readFileSync as ReadFileSyncFn } from '../node/file/index.js';
export declare const readFile: typeof ReadFileFn;
export declare const readFileSync: typeof ReadFileSyncFn;
import type { getStat as GetStatFn, getStatSync as GetStatSyncFn, readFileText as ReadFileTextFn, readFileTextSync as ReadFileTextSyncFn } from '../node/file/index.js';
export declare const readFileText: typeof ReadFileTextFn;
export declare const readFileTextSync: typeof ReadFileTextSyncFn;
export declare const getStat: typeof GetStatFn;
export declare const getStatSync: typeof GetStatSyncFn;
//# sourceMappingURL=file.d.ts.map
import { getDefaultCSpellIO } from '../CSpellIONode.js';
import { toError } from '../errors/index.js';
export const readFile = function (filename, encoding) {
export const readFileText = function (filename, encoding) {
return getDefaultCSpellIO()

@@ -8,3 +8,3 @@ .readFile(filename, encoding)

};
export const readFileSync = function (filename, encoding) {
export const readFileTextSync = function (filename, encoding) {
return getDefaultCSpellIO().readFileSync(filename, encoding).content;

@@ -11,0 +11,0 @@ };

export { writeToFile, writeToFileIterable, writeToFileIterable as writeToFileIterableP } from './../node/file/index.js';
export { getStat, getStatSync, readFile, readFileSync } from './file.js';
export { getStat, getStatSync, readFileText, readFileTextSync } from './file.js';
//# sourceMappingURL=index.d.ts.map
export { writeToFile, writeToFileIterable, writeToFileIterable as writeToFileIterableP } from './../node/file/index.js';
export { getStat, getStatSync, readFile, readFileSync } from './file.js';
export { getStat, getStatSync, readFileText, readFileTextSync } from './file.js';

@@ -6,2 +6,3 @@ import { createResponse, createResponseFail, isServiceResponseFailure, isServiceResponseSuccess, } from '@cspell/cspell-service-bus';

import { gunzipSync, gzipSync } from 'zlib';
import { arrayBufferViewToBuffer } from '../../common/arrayBuffers.js';
import { decode } from '../../common/encode-decode.js';

@@ -38,7 +39,11 @@ import { toError } from '../../errors/index.js';

}
return createResponse(res.value.then((res) => ({
url,
content: bufferToText(res.content, encoding),
baseFilename: res.baseFilename,
})));
return createResponse(res.value.then((res) => {
const content = bufferToText(res.content, encoding);
return {
url,
baseFilename: res.baseFilename,
encoding,
...content,
};
}));
}, undefined, 'Node: Read Text File.');

@@ -56,4 +61,5 @@ /**

return createResponse({
encoding,
...res.value,
content: bufferToText(res.value.content, encoding),
...bufferToText(res.value.content, encoding),
});

@@ -97,4 +103,7 @@ }, undefined, 'Node: Sync Read Text File.');

}, undefined, 'Node: Read data: urls.');
function bufferToText(buf, encoding) {
return buf[0] === 0x1f && buf[1] === 0x8b ? decode(gunzipSync(buf), encoding) : decode(buf, encoding);
function bufferToText(data, encoding) {
const buf = arrayBufferViewToBuffer(data);
const gz = buf[0] === 0x1f && buf[1] === 0x8b;
const content = gz ? decode(gunzipSync(buf), encoding) : decode(buf, encoding);
return { content, gz };
}

@@ -101,0 +110,0 @@ /**

export { toArray as asyncIterableToArray } from './async/asyncIterable.js';
export type { CSpellIO } from './CSpellIO.js';
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js';
export { getStat, getStatSync, readFile, readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
export type { Stats } from './models/Stats.js';
export { encodeDataUrl, toDataUrl } from './node/dataUrl.js';
//# sourceMappingURL=index.d.ts.map
export { toArray as asyncIterableToArray } from './async/asyncIterable.js';
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js';
export { getStat, getStatSync, readFile, readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
export { encodeDataUrl, toDataUrl } from './node/dataUrl.js';

@@ -1,2 +0,2 @@

export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'binary' | 'latin1' | 'hex';
export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'utf16be' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'binary' | 'latin1' | 'hex';
//# sourceMappingURL=BufferEncoding.d.ts.map

@@ -1,3 +0,3 @@

/// <reference types="node" />
export interface FileResource {
import type { BufferEncoding } from './BufferEncoding.js';
export interface FileReference {
/**

@@ -7,6 +7,8 @@ * The URL of the File

url: URL;
}
export interface FileResource extends FileReference {
/**
* The contents of the file
*/
content: string | Buffer;
content: string | ArrayBufferView;
/**

@@ -17,9 +19,19 @@ * The filename of the file if known.

baseFilename?: string | undefined;
/**
* - `true` if the content had been gzip compressed.
* - `false` if the content was NOT gzip compressed.
* - `undefined` if it is unknown
*/
gz?: boolean;
}
export interface TextFileResource extends FileResource {
content: string;
/**
* The encoding used to decode the file.
*/
encoding: BufferEncoding;
}
export interface BinaryFileResource extends FileResource {
content: Buffer;
content: ArrayBufferView;
}
//# sourceMappingURL=FileResource.d.ts.map
import type { BufferEncoding } from '../../models/BufferEncoding.js';
export declare function readFile(filename: string | URL, encoding?: BufferEncoding): Promise<string>;
export declare function readFileSync(filename: string, encoding?: BufferEncoding): string;
export declare function readFileText(filename: string | URL, encoding?: BufferEncoding): Promise<string>;
export declare function readFileTextSync(filename: string, encoding?: BufferEncoding): string;
//# sourceMappingURL=fileReader.d.ts.map

@@ -15,3 +15,3 @@ // cSpell:ignore curr

const pipeline = promisify(Stream.pipeline);
export async function readFile(filename, encoding) {
export async function readFileText(filename, encoding) {
const url = toURL(filename);

@@ -21,10 +21,10 @@ if (!isSupportedURL(url)) {

}
return isFileURL(url) ? _readFile(url, encoding) : _fetchURL(url, encoding);
return isFileURL(url) ? _readFileText(url, encoding) : _fetchTextFromURL(url, encoding);
}
function _readFile(url, encoding) {
function _readFileText(url, encoding) {
// Convert it to a string because Yarn2 cannot handle URLs.
const filename = fileURLToPath(url);
return _read(() => fs.createReadStream(filename), isZipped(filename), encoding);
return _readText(() => fs.createReadStream(filename), isZipped(filename), encoding);
}
async function _fetchURL(url, encoding) {
async function _fetchTextFromURL(url, encoding) {
const response = await fetch(url);

@@ -34,20 +34,28 @@ if (!response.ok) {

}
return _read(() => response.body, isZipped(url), encoding);
return _readText(() => response.body, isZipped(url), encoding);
}
async function _read(getStream, isZipped, encoding) {
async function _readText(getStream, isZipped, encoding) {
const stream = getStream();
const decoder = createDecoderTransformer(encoding);
const collector = createCollector(encoding || defaultEncoding);
const collector = createTextCollector(encoding || defaultEncoding);
return isZipped ? pipeline(stream, zlib.createGunzip(), decoder, collector) : pipeline(stream, decoder, collector);
}
export function readFileSync(filename, encoding) {
export function readFileTextSync(filename, encoding) {
const rawData = fs.readFileSync(filename);
const data = isZipped(filename) ? zlib.gunzipSync(rawData) : rawData;
return !encoding || encoding.startsWith('utf') ? decode(data) : data.toString(encoding);
return !encoding || encoding.startsWith('utf')
? decode(data)
: encoding === 'utf16be'
? data.swap16().toString('utf16le')
: data.toString(encoding);
}
function createCollector(encoding) {
function createTextCollector(encoding) {
async function collect(iterable) {
const buf = [];
for await (const sb of iterable) {
buf.push(typeof sb === 'string' ? sb : sb.toString(encoding));
buf.push(typeof sb === 'string'
? sb
: encoding === 'utf16be'
? sb.swap16().toString('utf16le')
: sb.toString(encoding));
}

@@ -54,0 +62,0 @@ return buf.join('');

@@ -1,4 +0,4 @@

export { readFile, readFileSync } from './fileReader.js';
export { readFileText, readFileTextSync } from './fileReader.js';
export { writeToFile, writeToFileIterable } from './fileWriter.js';
export { getStat, getStatSync } from './stat.js';
//# sourceMappingURL=index.d.ts.map

@@ -1,3 +0,3 @@

export { readFile, readFileSync } from './fileReader.js';
export { readFileText, readFileTextSync } from './fileReader.js';
export { writeToFile, writeToFileIterable } from './fileWriter.js';
export { getStat, getStatSync } from './stat.js';
export { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync } from './RequestFsReadBinaryFile.js';
export { RequestFsReadFile } from './RequestFsReadFile.js';
export { RequestFsReadFileSync } from './RequestFsReadFileSync.js';
export { RequestFsReadFileText as RequestFsReadFile } from './RequestFsReadFile.js';
export { RequestFsReadFileTextSync as RequestFsReadFileSync } from './RequestFsReadFileSync.js';
export { RequestFsStat, RequestFsStatSync } from './RequestFsStat.js';

@@ -5,0 +5,0 @@ export { RequestFsWriteFile } from './RequestFsWriteFile.js';

export { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync } from './RequestFsReadBinaryFile.js';
export { RequestFsReadFile } from './RequestFsReadFile.js';
export { RequestFsReadFileSync } from './RequestFsReadFileSync.js';
export { RequestFsReadFileText as RequestFsReadFile } from './RequestFsReadFile.js';
export { RequestFsReadFileTextSync as RequestFsReadFileSync } from './RequestFsReadFileSync.js';
export { RequestFsStat, RequestFsStatSync } from './RequestFsStat.js';
export { RequestFsWriteFile } from './RequestFsWriteFile.js';
export { RequestZlibInflate } from './RequestZlibInflate.js';

@@ -1,3 +0,3 @@

/// <reference types="node" />
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus';
import type { BufferEncoding } from '../models/BufferEncoding';
import type { TextFileResource } from '../models/FileResource.js';

@@ -8,5 +8,5 @@ interface RequestParams {

}
export declare const RequestFsReadFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<TextFileResource>>, RequestParams, "fs:readFile">;
export type RequestFsReadFile = ServiceRequestFactoryRequestType<typeof RequestFsReadFile>;
export declare const RequestFsReadFileText: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<TextFileResource>>, RequestParams, "fs:readFile">;
export type RequestFsReadFileText = ServiceRequestFactoryRequestType<typeof RequestFsReadFileText>;
export {};
//# sourceMappingURL=RequestFsReadFile.d.ts.map
import { requestFactory } from '@cspell/cspell-service-bus';
const RequestType = 'fs:readFile';
export const RequestFsReadFile = requestFactory(RequestType);
export const RequestFsReadFileText = requestFactory(RequestType);

@@ -1,3 +0,3 @@

/// <reference types="node" />
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus';
import type { BufferEncoding } from '../models/BufferEncoding';
import type { TextFileResource } from '../models/FileResource.js';

@@ -8,5 +8,5 @@ interface RequestParams {

}
export declare const RequestFsReadFileSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, TextFileResource>, RequestParams, "fs:readFileSync">;
export type RequestFsReadFileSync = ServiceRequestFactoryRequestType<typeof RequestFsReadFileSync>;
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, TextFileResource>, RequestParams, "fs:readFileSync">;
export type RequestFsReadFileTextSync = ServiceRequestFactoryRequestType<typeof RequestFsReadFileTextSync>;
export {};
//# sourceMappingURL=RequestFsReadFileSync.d.ts.map
import { requestFactory } from '@cspell/cspell-service-bus';
const RequestType = 'fs:readFileSync';
export const RequestFsReadFileSync = requestFactory(RequestType);
export const RequestFsReadFileTextSync = requestFactory(RequestType);
{
"name": "cspell-io",
"version": "7.0.0-alpha.2",
"version": "7.0.0",
"description": "A library of useful I/O functions used across various cspell tools.",

@@ -53,10 +53,10 @@ "type": "commonjs",

"devDependencies": {
"@types/node-fetch": "^2.6.3",
"@types/node-fetch": "^2.6.4",
"lorem-ipsum": "^2.0.8"
},
"dependencies": {
"@cspell/cspell-service-bus": "7.0.0-alpha.2",
"node-fetch": "^2.6.9"
"@cspell/cspell-service-bus": "7.0.0",
"node-fetch": "^2.6.12"
},
"gitHead": "a1b7c5daeef5afdb14d6444318f450b9fd9c035a"
"gitHead": "52960d5ed75655978f9b633f44fd106937a63cd7"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc