cspell-io
Advanced tools
Comparing version 8.0.0 to 8.1.0
/// <reference types="node" resolution-mode="require"/> | ||
export declare function toUint8Array(data: ArrayBufferView): Uint8Array; | ||
/** | ||
* Treat a ArrayBufferView as a Uint8Array. | ||
* The Uint8Array will share the same underlying ArrayBuffer. | ||
* @param data - source data | ||
* @returns Uint8Array | ||
*/ | ||
export declare function asUint8Array(data: ArrayBufferView): Uint8Array; | ||
export declare function arrayBufferViewToBuffer(data: ArrayBufferView): Buffer; | ||
@@ -17,2 +23,19 @@ /** | ||
export declare function sliceView(data: ArrayBufferView, byteOffset: number, byteLength?: number): ArrayBufferView; | ||
/** | ||
* Swap the bytes in a buffer. | ||
* @param data - data to swap | ||
* @returns data | ||
*/ | ||
declare function swap16Poly(data: ArrayBufferView): ArrayBufferView; | ||
/** | ||
* Swap the bytes in a buffer. | ||
* @param data - data to swap | ||
* @returns data | ||
*/ | ||
export declare function swap16(data: ArrayBufferView): ArrayBufferView; | ||
export declare function swapBytes(data: ArrayBufferView): ArrayBufferView; | ||
export declare const __debug__: { | ||
swap16Poly: typeof swap16Poly; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=arrayBuffers.d.ts.map |
@@ -1,2 +0,8 @@ | ||
export function toUint8Array(data) { | ||
/** | ||
* Treat a ArrayBufferView as a Uint8Array. | ||
* The Uint8Array will share the same underlying ArrayBuffer. | ||
* @param data - source data | ||
* @returns Uint8Array | ||
*/ | ||
export function asUint8Array(data) { | ||
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength); | ||
@@ -38,2 +44,32 @@ } | ||
} | ||
/** | ||
* Swap the bytes in a buffer. | ||
* @param data - data to swap | ||
* @returns data | ||
*/ | ||
function swap16Poly(data) { | ||
const view = new DataView(data.buffer, data.byteOffset, data.byteLength); | ||
for (let i = 0; i < view.byteLength; i += 2) { | ||
view.setUint16(i, view.getUint16(i, false), true); | ||
} | ||
return data; | ||
} | ||
/** | ||
* Swap the bytes in a buffer. | ||
* @param data - data to swap | ||
* @returns data | ||
*/ | ||
export function swap16(data) { | ||
if (typeof Buffer !== 'undefined') { | ||
return arrayBufferViewToBuffer(data).swap16(); | ||
} | ||
return swap16Poly(data); | ||
} | ||
export function swapBytes(data) { | ||
const buf = copyArrayBufferView(data); | ||
return swap16(buf); | ||
} | ||
export const __debug__ = { | ||
swap16Poly, | ||
}; | ||
//# sourceMappingURL=arrayBuffers.js.map |
@@ -1,4 +0,6 @@ | ||
import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
export type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
export type BufferEncodingExt = BufferEncoding | 'utf16be'; | ||
import type { BufferEncoding, TextEncoding } from '../models/BufferEncoding.js'; | ||
export type { BufferEncoding, TextEncoding } from '../models/BufferEncoding.js'; | ||
type TextEncodingExtra = 'utf-16be' | 'utf-16le' | 'utf16be' | 'utf16le'; | ||
export type BufferEncodingExt = BufferEncoding | TextEncodingExtra; | ||
export type TextEncodingExt = TextEncoding | TextEncodingExtra; | ||
//# sourceMappingURL=BufferEncoding.d.ts.map |
@@ -1,7 +0,6 @@ | ||
import type { BufferEncodingExt } from './BufferEncoding.js'; | ||
import type { BufferEncodingExt, TextEncodingExt } from './BufferEncoding.js'; | ||
export declare function decodeUtf16LE(data: ArrayBufferView): string; | ||
export declare function decodeUtf16BE(buf: ArrayBufferView): string; | ||
export declare function decodeUtf16BE(data: ArrayBufferView): string; | ||
export declare function decodeToString(data: ArrayBufferView, encoding?: TextEncodingExt): 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; | ||
@@ -11,2 +10,6 @@ export declare function encodeUtf16LE(str: string, bom?: boolean): ArrayBufferView; | ||
export declare function calcEncodingFromBom(data: ArrayBufferView): 'utf16be' | 'utf16le' | undefined; | ||
export declare class UnsupportedEncodingError extends Error { | ||
constructor(encoding: string); | ||
} | ||
export declare function isGZipped(data: ArrayBufferView | string): boolean; | ||
//# sourceMappingURL=encode-decode.d.ts.map |
@@ -1,43 +0,62 @@ | ||
import { arrayBufferViewToBuffer, copyArrayBufferView, toUint8Array } from './arrayBuffers.js'; | ||
import { gunzipSync } from 'node:zlib'; | ||
import { arrayBufferViewToBuffer, asUint8Array, swap16, swapBytes } from './arrayBuffers.js'; | ||
const BOM_BE = 0xfeff; | ||
const BOM_LE = 0xfffe; | ||
const decoderUTF8 = new TextDecoder('utf-8'); | ||
const decoderUTF16LE = new TextDecoder('utf-16le'); | ||
const decoderUTF16BE = createTextDecoderUtf16BE(); | ||
// const encoderUTF8 = new TextEncoder(); | ||
// const encoderUTF16LE = new TextEncoder('utf-16le'); | ||
export function decodeUtf16LE(data) { | ||
let buf = arrayBufferViewToBuffer(data); | ||
const buf = asUint8Array(data); | ||
const bom = (buf[0] << 8) | buf[1]; | ||
buf = bom === BOM_LE ? buf.subarray(2) : buf; | ||
return buf.toString('utf16le'); | ||
return decoderUTF16LE.decode(bom === BOM_LE ? buf.subarray(2) : buf); | ||
} | ||
export function decodeUtf16BE(buf) { | ||
return decodeUtf16LE(swapBytes(buf)); | ||
export function decodeUtf16BE(data) { | ||
const buf = asUint8Array(data); | ||
const bom = (buf[0] << 8) | buf[1]; | ||
return decoderUTF16BE.decode(bom === BOM_BE ? buf.subarray(2) : buf); | ||
} | ||
export function decode(data, encoding) { | ||
const buf = arrayBufferViewToBuffer(data); | ||
export function decodeToString(data, encoding) { | ||
if (isGZipped(data)) { | ||
return decodeToString(decompressBuffer(data), encoding); | ||
} | ||
const buf = asUint8Array(data); | ||
const bom = (buf[0] << 8) | buf[1]; | ||
if (bom === BOM_BE || (buf[0] === 0 && buf[1] !== 0)) | ||
return decodeUtf16BE(buf); | ||
if (bom === BOM_LE || (buf[0] !== 0 && buf[1] === 0)) | ||
return decodeUtf16LE(buf); | ||
if (!encoding) | ||
return decoderUTF8.decode(buf); | ||
switch (encoding) { | ||
case 'utf-16be': | ||
case 'utf16be': | ||
return decodeUtf16BE(buf); | ||
case 'utf-16le': | ||
case 'utf16le': | ||
return decodeUtf16LE(buf); | ||
case 'utf-8': | ||
case 'utf8': | ||
return decoderUTF8.decode(buf); | ||
} | ||
if (buf.length < 2 || (encoding && !encoding.startsWith('utf'))) | ||
return buf.toString(encoding); | ||
const bom = (buf[0] << 8) | buf[1]; | ||
if (bom === BOM_BE || (buf[0] === 0 && buf[1] !== 0)) | ||
return decodeUtf16BE(buf); | ||
if (bom === BOM_LE || (buf[0] !== 0 && buf[1] === 0)) | ||
return decodeUtf16LE(buf); | ||
return buf.toString(encoding); | ||
throw new UnsupportedEncodingError(encoding); | ||
} | ||
export function swapBytesInPlace(data) { | ||
const buf = arrayBufferViewToBuffer(data); | ||
buf.swap16(); | ||
return buf; | ||
export function decode(data, encoding) { | ||
switch (encoding) { | ||
case 'base64': | ||
case 'base64url': | ||
case 'hex': | ||
return arrayBufferViewToBuffer(data).toString(encoding); | ||
} | ||
const result = decodeToString(data, encoding); | ||
// console.log('decode %o', { data, encoding, result }); | ||
return result; | ||
} | ||
export function swapBytes(data) { | ||
const buf = copyArrayBufferView(data); | ||
return swapBytesInPlace(buf); | ||
} | ||
export function encodeString(str, encoding, bom) { | ||
switch (encoding) { | ||
case 'utf-16be': | ||
case 'utf16be': | ||
return encodeUtf16BE(str, bom); | ||
case 'utf-16le': | ||
case 'utf16le': | ||
@@ -59,6 +78,6 @@ return encodeUtf16LE(str, bom); | ||
export function encodeUtf16BE(str, bom = true) { | ||
return swapBytesInPlace(encodeUtf16LE(str, bom)); | ||
return swap16(encodeUtf16LE(str, bom)); | ||
} | ||
export function calcEncodingFromBom(data) { | ||
const buf = toUint8Array(data); | ||
const buf = asUint8Array(data); | ||
if (buf.length < 2) | ||
@@ -74,2 +93,33 @@ return undefined; | ||
} | ||
function createTextDecoderUtf16BE() { | ||
try { | ||
const decoder = new TextDecoder('utf-16be'); | ||
return decoder; | ||
} | ||
catch (e) { | ||
return { | ||
encoding: 'utf-16be', | ||
fatal: false, | ||
ignoreBOM: false, | ||
decode: (input) => decoderUTF16LE.decode(swapBytes(input)), | ||
}; | ||
} | ||
} | ||
export class UnsupportedEncodingError extends Error { | ||
constructor(encoding) { | ||
super(`Unsupported encoding: ${encoding}`); | ||
} | ||
} | ||
export function isGZipped(data) { | ||
if (typeof data === 'string') | ||
return false; | ||
const buf = asUint8Array(data); | ||
return buf[0] === 0x1f && buf[1] === 0x8b; | ||
} | ||
function decompressBuffer(data) { | ||
if (!isGZipped(data)) | ||
return data; | ||
const buf = arrayBufferViewToBuffer(data); | ||
return gunzipSync(buf); | ||
} | ||
//# sourceMappingURL=encode-decode.js.map |
@@ -1,2 +0,1 @@ | ||
import { sliceView } from './arrayBuffers.js'; | ||
import { calcEncodingFromBom, decode, decodeUtf16BE, decodeUtf16LE, encodeString } from './encode-decode.js'; | ||
@@ -32,10 +31,10 @@ export function createDecoderTransformer(encoding) { | ||
const _encoding = calcEncodingFromBom(sb); | ||
if (_encoding === 'utf16le') { | ||
if (_encoding === 'utf16le' || encoding === 'utf16le' || encoding === 'utf-16le') { | ||
decoder = decodeUtf16LE; | ||
yield decoder(sliceView(sb, 2)); | ||
yield decoder(sb); | ||
continue; | ||
} | ||
if (_encoding === 'utf16be') { | ||
if (_encoding === 'utf16be' || encoding === 'utf16be' || encoding === 'utf-16be') { | ||
decoder = decodeUtf16BE; | ||
yield decoder(sliceView(sb, 2)); | ||
yield decoder(sb); | ||
continue; | ||
@@ -42,0 +41,0 @@ } |
import type { BufferEncoding } from './models/BufferEncoding.js'; | ||
import type { TextFileResource } from './models/FileResource.js'; | ||
import type { FileReference, FileResource, UrlOrFilename, UrlOrReference } from './models/FileResource.js'; | ||
import type { Stats } from './models/index.js'; | ||
export type UrlOrFilename = string | URL; | ||
export interface CSpellIO { | ||
@@ -12,3 +11,3 @@ /** | ||
*/ | ||
readFile(uriOrFilename: UrlOrFilename, encoding?: BufferEncoding): Promise<TextFileResource>; | ||
readFile(uriOrFilename: UrlOrReference, encoding?: BufferEncoding): Promise<FileResource>; | ||
/** | ||
@@ -21,3 +20,3 @@ * Read a file in Sync mode. | ||
*/ | ||
readFileSync(uriOrFilename: UrlOrFilename, encoding?: BufferEncoding): TextFileResource; | ||
readFileSync(uriOrFilename: UrlOrReference, encoding?: BufferEncoding): FileResource; | ||
/** | ||
@@ -29,3 +28,3 @@ * Write content to a file using utf-8 encoding. | ||
*/ | ||
writeFile(uriOrFilename: UrlOrFilename, content: string): Promise<void>; | ||
writeFile(uriOrFilename: UrlOrReference, content: string | ArrayBufferView): Promise<FileReference>; | ||
/** | ||
@@ -36,3 +35,3 @@ * Get Stats on a uri. | ||
*/ | ||
getStat(uriOrFilename: UrlOrFilename): Promise<Stats>; | ||
getStat(uriOrFilename: UrlOrReference): Promise<Stats>; | ||
/** | ||
@@ -43,3 +42,3 @@ * Get Stats on a uri. | ||
*/ | ||
getStatSync(uriOrFilename: UrlOrFilename): Stats; | ||
getStatSync(uriOrFilename: UrlOrReference): Stats; | ||
/** | ||
@@ -54,7 +53,16 @@ * Compare two Stats. | ||
* Convert a string to a URL | ||
* @param uriOrFilename - string or URL to convert. | ||
* @param urlOrFilename - string or URL to convert. | ||
* If it is a URL, then it is just returned as is. | ||
* If is is a string and fully formed URL, then it is parsed. | ||
* If it is a string without a protocol/scheme it is assumed to be relative to `relativeTo`. | ||
* @param relativeTo - optional | ||
*/ | ||
toURL(uriOrFilename: UrlOrFilename): URL; | ||
toURL(urlOrFilename: UrlOrReference, relativeTo?: string | URL): URL; | ||
/** | ||
* Convert a string to a File URL | ||
* @param urlOrFilename - string or URL to convert. | ||
* @param relativeTo - optional | ||
*/ | ||
toFileURL(urlOrFilename: UrlOrFilename, relativeTo?: string | URL): URL; | ||
/** | ||
* Try to determine the base name of a URL. | ||
@@ -64,13 +72,20 @@ * | ||
* | ||
* Example: `data:text/plain;charset=utf8;filename=hello.txt,Hello` would have a filename of `hello.txt` | ||
* @param uriOrFilename - string or URL to extract the basename from. | ||
* Example: | ||
* - `data:text/plain;charset=utf8;filename=hello.txt,Hello` would have a filename of `hello.txt` | ||
* - `file:///user/project/cspell.config.yaml` would have a filename of `cspell.config.yaml` | ||
* - `https://raw.guc.com/sss/cspell/main/cspell.schema.json` would have a filename of `cspell.schema.json` | ||
* @param urlOrFilename - string or URL to extract the basename from. | ||
*/ | ||
uriBasename(uriOrFilename: UrlOrFilename): string; | ||
urlBasename(urlOrFilename: UrlOrReference): string; | ||
/** | ||
* Try to determine the directory URL of the uri. | ||
* | ||
* @param uriOrFilename - string or URL to extract the basename from. | ||
* Example: | ||
* - `file:///user/local/file.txt` becomes `file:///user/local/` | ||
* - `file:///user/local/` becomes `file:///user/` | ||
* | ||
* @param urlOrFilename - string or URL | ||
*/ | ||
uriDirname(uriOrFilename: UrlOrFilename): URL; | ||
urlDirname(urlOrFilename: UrlOrReference): URL; | ||
} | ||
//# sourceMappingURL=CSpellIO.d.ts.map |
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'; | ||
import type { FileReference, FileResource, UrlOrReference } from './models/FileResource.js'; | ||
import type { Stats } from './models/Stats.js'; | ||
@@ -9,13 +9,14 @@ export declare class CSpellIONode implements CSpellIO { | ||
constructor(serviceBus?: ServiceBus); | ||
readFile(uriOrFilename: string | URL, encoding?: BufferEncoding): Promise<TextFileResource>; | ||
readFileSync(uriOrFilename: string | URL, encoding?: BufferEncoding): TextFileResource; | ||
writeFile(uriOrFilename: string | URL, content: string): Promise<void>; | ||
getStat(uriOrFilename: string | URL): Promise<Stats>; | ||
getStatSync(uriOrFilename: string | URL): Stats; | ||
readFile(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): Promise<FileResource>; | ||
readFileSync(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): FileResource; | ||
writeFile(urlOrFilename: UrlOrReference, content: string | ArrayBufferView): Promise<FileReference>; | ||
getStat(urlOrFilename: UrlOrReference): Promise<Stats>; | ||
getStatSync(urlOrFilename: UrlOrReference): Stats; | ||
compareStats(left: Stats, right: Stats): number; | ||
toURL(uriOrFilename: string | URL): URL; | ||
uriBasename(uriOrFilename: string | URL): string; | ||
uriDirname(uriOrFilename: string | URL): URL; | ||
toURL(urlOrFilename: UrlOrReference, relativeTo?: string | URL): URL; | ||
toFileURL(urlOrFilename: UrlOrReference, relativeTo?: string | URL): URL; | ||
urlBasename(urlOrFilename: UrlOrReference): string; | ||
urlDirname(urlOrFilename: UrlOrReference): URL; | ||
} | ||
export declare function getDefaultCSpellIO(): CSpellIO; | ||
//# sourceMappingURL=CSpellIONode.d.ts.map |
import { isServiceResponseSuccess, ServiceBus } from '@cspell/cspell-service-bus'; | ||
import { isFileReference, toFileReference } from './common/CFileReference.js'; | ||
import { CFileResource } from './common/CFileResource.js'; | ||
import { compareStats } from './common/stat.js'; | ||
import { ErrorNotImplemented } from './errors/ErrorNotImplemented.js'; | ||
import { ErrorNotImplemented } from './errors/errors.js'; | ||
import { registerHandlers } from './handlers/node/file.js'; | ||
import { toURL, urlBasename, urlDirname } from './node/file/util.js'; | ||
import { toFileURL, toURL, urlBasename, urlDirname } from './node/file/url.js'; | ||
import { RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, } from './requests/index.js'; | ||
@@ -14,5 +16,5 @@ let defaultCSpellIONode = undefined; | ||
} | ||
readFile(uriOrFilename, encoding = 'utf8') { | ||
const url = toURL(uriOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsReadFile.create({ url, encoding })); | ||
readFile(urlOrFilename, encoding) { | ||
const ref = toFileReference(urlOrFilename, encoding); | ||
const res = this.serviceBus.dispatch(RequestFsReadFile.create(ref)); | ||
if (!isServiceResponseSuccess(res)) { | ||
@@ -23,5 +25,5 @@ throw genError(res.error, 'readFile'); | ||
} | ||
readFileSync(uriOrFilename, encoding = 'utf8') { | ||
const url = toURL(uriOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsReadFileSync.create({ url, encoding })); | ||
readFileSync(urlOrFilename, encoding) { | ||
const ref = toFileReference(urlOrFilename, encoding); | ||
const res = this.serviceBus.dispatch(RequestFsReadFileSync.create(ref)); | ||
if (!isServiceResponseSuccess(res)) { | ||
@@ -32,5 +34,6 @@ throw genError(res.error, 'readFileSync'); | ||
} | ||
writeFile(uriOrFilename, content) { | ||
const url = toURL(uriOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsWriteFile.create({ url, content })); | ||
writeFile(urlOrFilename, content) { | ||
const ref = toFileReference(urlOrFilename); | ||
const fileResource = CFileResource.from(ref, content); | ||
const res = this.serviceBus.dispatch(RequestFsWriteFile.create(fileResource)); | ||
if (!isServiceResponseSuccess(res)) { | ||
@@ -41,5 +44,5 @@ throw genError(res.error, 'writeFile'); | ||
} | ||
getStat(uriOrFilename) { | ||
const url = toURL(uriOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsStat.create({ url })); | ||
getStat(urlOrFilename) { | ||
const ref = toFileReference(urlOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsStat.create(ref)); | ||
if (!isServiceResponseSuccess(res)) { | ||
@@ -50,5 +53,5 @@ throw genError(res.error, 'getStat'); | ||
} | ||
getStatSync(uriOrFilename) { | ||
const url = toURL(uriOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsStatSync.create({ url })); | ||
getStatSync(urlOrFilename) { | ||
const ref = toFileReference(urlOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsStatSync.create(ref)); | ||
if (!isServiceResponseSuccess(res)) { | ||
@@ -62,11 +65,18 @@ throw genError(res.error, 'getStatSync'); | ||
} | ||
toURL(uriOrFilename) { | ||
return toURL(uriOrFilename); | ||
toURL(urlOrFilename, relativeTo) { | ||
if (isFileReference(urlOrFilename)) | ||
return urlOrFilename.url; | ||
return toURL(urlOrFilename, relativeTo); | ||
} | ||
uriBasename(uriOrFilename) { | ||
return urlBasename(uriOrFilename); | ||
toFileURL(urlOrFilename, relativeTo) { | ||
if (isFileReference(urlOrFilename)) | ||
return urlOrFilename.url; | ||
return toFileURL(urlOrFilename, relativeTo); | ||
} | ||
uriDirname(uriOrFilename) { | ||
return urlDirname(uriOrFilename); | ||
urlBasename(urlOrFilename) { | ||
return urlBasename(this.toURL(urlOrFilename)); | ||
} | ||
urlDirname(urlOrFilename) { | ||
return urlDirname(this.toURL(urlOrFilename)); | ||
} | ||
} | ||
@@ -73,0 +83,0 @@ function genError(err, alt) { |
import type { CSpellIO } from './CSpellIO.js'; | ||
import type { TextFileResource } from './models/FileResource.js'; | ||
import type { FileReference, FileResource, UrlOrFilename, UrlOrReference } from './models/FileResource.js'; | ||
import type { Stats } from './models/Stats.js'; | ||
export declare class CSpellIOWeb implements CSpellIO { | ||
readFile(_uriOrFilename: string | URL): Promise<TextFileResource>; | ||
readFileSync(_uriOrFilename: string | URL): TextFileResource; | ||
writeFile(_uriOrFilename: string | URL, _content: string): Promise<void>; | ||
readFile(_uriOrFilename: string | URL): Promise<FileResource>; | ||
readFileSync(_uriOrFilename: string | URL): FileResource; | ||
writeFile(_uriOrFilename: UrlOrReference, _content: string | ArrayBufferView): Promise<FileReference>; | ||
getStat(_uriOrFilename: string | URL): Promise<Stats>; | ||
getStatSync(_uriOrFilename: string | URL): Stats; | ||
compareStats(left: Stats, right: Stats): number; | ||
toURL(_uriOrFilename: string | URL): URL; | ||
uriBasename(_uriOrFilename: string | URL): string; | ||
uriDirname(_uriOrFilename: string | URL): URL; | ||
toURL(_uriOrFilename: UrlOrReference): URL; | ||
toFileURL(_urlOrFilename: UrlOrFilename, _relativeTo?: string | URL | undefined): URL; | ||
urlBasename(_uriOrFilename: string | URL): string; | ||
urlDirname(_uriOrFilename: string | URL): URL; | ||
} | ||
//# sourceMappingURL=CSpellIOWeb.d.ts.map |
import { compareStats } from './common/stat.js'; | ||
import { ErrorNotImplemented } from './errors/ErrorNotImplemented.js'; | ||
import { ErrorNotImplemented } from './errors/errors.js'; | ||
export class CSpellIOWeb { | ||
@@ -25,6 +25,9 @@ readFile(_uriOrFilename) { | ||
} | ||
uriBasename(_uriOrFilename) { | ||
toFileURL(_urlOrFilename, _relativeTo) { | ||
throw new ErrorNotImplemented('toFileURL'); | ||
} | ||
urlBasename(_uriOrFilename) { | ||
throw new ErrorNotImplemented('uriBasename'); | ||
} | ||
uriDirname(_uriOrFilename) { | ||
urlDirname(_uriOrFilename) { | ||
throw new ErrorNotImplemented('uriDirname'); | ||
@@ -31,0 +34,0 @@ } |
export function toError(e) { | ||
if (e instanceof Error) | ||
return e; | ||
if (typeof e === 'object' && e && typeof e.message === 'string') { | ||
return e; | ||
if (typeof e === 'object' && e && 'message' in e && typeof e.message === 'string') { | ||
return new Error(e.message, { cause: e }); | ||
} | ||
@@ -7,0 +7,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any |
export { toError } from './error.js'; | ||
export { ErrorNotImplemented } from './ErrorNotImplemented.js'; | ||
export { ErrorNotImplemented } from './errors.js'; | ||
//# sourceMappingURL=index.d.ts.map |
export { toError } from './error.js'; | ||
export { ErrorNotImplemented } from './ErrorNotImplemented.js'; | ||
export { ErrorNotImplemented } from './errors.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,6 +0,7 @@ | ||
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; | ||
import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
import type { Stats } from '../models/index.js'; | ||
export declare function readFileText(filename: string | URL, encoding?: BufferEncoding): Promise<string>; | ||
export declare function readFileTextSync(filename: string | URL, encoding?: BufferEncoding): string; | ||
export declare function getStat(filenameOrUri: string): Promise<Stats | Error>; | ||
export declare function getStatSync(filenameOrUri: string): Stats | Error; | ||
//# sourceMappingURL=file.d.ts.map |
import { getDefaultCSpellIO } from '../CSpellIONode.js'; | ||
import { toError } from '../errors/index.js'; | ||
export const readFileText = function (filename, encoding) { | ||
return getDefaultCSpellIO() | ||
.readFile(filename, encoding) | ||
.then((fr) => fr.content); | ||
}; | ||
export const readFileTextSync = function (filename, encoding) { | ||
return getDefaultCSpellIO().readFileSync(filename, encoding).content; | ||
}; | ||
export const getStat = function (filenameOrUri) { | ||
return getDefaultCSpellIO().getStat(filenameOrUri).catch(toError); | ||
}; | ||
export const getStatSync = function (filenameOrUri) { | ||
export async function readFileText(filename, encoding) { | ||
const fr = await getDefaultCSpellIO().readFile(filename, encoding); | ||
return fr.getText(); | ||
} | ||
export function readFileTextSync(filename, encoding) { | ||
return getDefaultCSpellIO().readFileSync(filename, encoding).getText(); | ||
} | ||
export async function getStat(filenameOrUri) { | ||
try { | ||
return await getDefaultCSpellIO().getStat(filenameOrUri); | ||
} | ||
catch (e) { | ||
return toError(e); | ||
} | ||
} | ||
export function getStatSync(filenameOrUri) { | ||
try { | ||
return getDefaultCSpellIO().getStatSync(filenameOrUri); | ||
@@ -21,3 +25,3 @@ } | ||
} | ||
}; | ||
} | ||
//# sourceMappingURL=file.js.map |
@@ -1,17 +0,21 @@ | ||
import { createResponse, createResponseFail, isServiceResponseFailure, isServiceResponseSuccess, } from '@cspell/cspell-service-bus'; | ||
import assert from 'assert'; | ||
import { createResponse, createResponseFail, isServiceResponseSuccess } from '@cspell/cspell-service-bus'; | ||
import { promises as fs, readFileSync, statSync } from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
import { gunzipSync, gzipSync } from 'zlib'; | ||
import { promisify } from 'util'; | ||
import { gunzipSync, gzip } from 'zlib'; | ||
import { arrayBufferViewToBuffer } from '../../common/arrayBuffers.js'; | ||
import { decode } from '../../common/encode-decode.js'; | ||
import { encodeString, isGZipped } from '../../common/encode-decode.js'; | ||
import { CFileResource } from '../../common/index.js'; | ||
import { assert } from '../../errors/assert.js'; | ||
import { toError } from '../../errors/index.js'; | ||
import { decodeDataUrl } from '../../node/dataUrl.js'; | ||
import { decodeDataUrl, guessMimeType, toDataUrl } from '../../node/dataUrl.js'; | ||
import { fetchURL } from '../../node/file/fetch.js'; | ||
import { getStatHttp } from '../../node/file/stat.js'; | ||
import { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync, RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, RequestZlibInflate, } from '../../requests/index.js'; | ||
import { urlBasename } from '../../node/file/url.js'; | ||
import { RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, RequestZlibInflate, } from '../../requests/index.js'; | ||
const isGzFileRegExp = /\.gz($|[?#])/; | ||
function isGzFile(url) { | ||
return isGzFileRegExp.test(url.pathname); | ||
return isGzFileRegExp.test(typeof url === 'string' ? url : url.pathname); | ||
} | ||
const pGzip = promisify(gzip); | ||
/* | ||
@@ -23,47 +27,16 @@ * NOTE: fileURLToPath is used because of yarn bug https://github.com/yarnpkg/berry/issues/899 | ||
*/ | ||
const handleRequestFsReadBinaryFile = RequestFsReadBinaryFile.createRequestHandler(({ params }) => createResponse(fs.readFile(fileURLToPath(params.url)).then((content) => ({ url: params.url, content }))), undefined, 'Node: Read Binary File.'); | ||
const handleRequestFsReadFile = RequestFsReadFile.createRequestHandler(({ params }) => { | ||
const baseFilename = urlBasename(params.url); | ||
return createResponse(fs | ||
.readFile(fileURLToPath(params.url)) | ||
.then((content) => CFileResource.from(params.url, content, params.encoding, baseFilename))); | ||
}, undefined, 'Node: Read Binary File.'); | ||
/** | ||
* Handle Binary File Sync Reads | ||
*/ | ||
const handleRequestFsReadBinaryFileSync = RequestFsReadBinaryFileSync.createRequestHandler(({ params }) => createResponse({ url: params.url, content: readFileSync(fileURLToPath(params.url)) }), undefined, 'Node: Sync Read Binary File.'); | ||
const handleRequestFsReadFileSync = RequestFsReadFileSync.createRequestHandler(({ params }) => createResponse(CFileResource.from({ ...params, content: readFileSync(fileURLToPath(params.url)) })), undefined, 'Node: Sync Read Binary File.'); | ||
/** | ||
* Handle UTF-8 Text File Reads | ||
*/ | ||
const handleRequestFsReadFile = RequestFsReadFile.createRequestHandler((req, _, dispatcher) => { | ||
const { url, encoding } = req.params; | ||
const res = dispatcher.dispatch(RequestFsReadBinaryFile.create({ url })); | ||
if (!isServiceResponseSuccess(res)) { | ||
assert(isServiceResponseFailure(res)); | ||
return createResponseFail(req, res.error); | ||
} | ||
return createResponse(res.value.then((res) => { | ||
const content = bufferToText(res.content, encoding); | ||
return { | ||
url, | ||
baseFilename: res.baseFilename, | ||
encoding, | ||
...content, | ||
}; | ||
})); | ||
}, undefined, 'Node: Read Text File.'); | ||
/** | ||
* Handle UTF-8 Text File Reads | ||
*/ | ||
const handleRequestFsReadFileSync = RequestFsReadFileSync.createRequestHandler((req, _, dispatcher) => { | ||
const { url, encoding } = req.params; | ||
const res = dispatcher.dispatch(RequestFsReadBinaryFileSync.create({ url })); | ||
if (!isServiceResponseSuccess(res)) { | ||
assert(isServiceResponseFailure(res)); | ||
return createResponseFail(req, res.error); | ||
} | ||
return createResponse({ | ||
encoding, | ||
...res.value, | ||
...bufferToText(res.value.content, encoding), | ||
}); | ||
}, undefined, 'Node: Sync Read Text File.'); | ||
/** | ||
* Handle deflating gzip data | ||
*/ | ||
const handleRequestZlibInflate = RequestZlibInflate.createRequestHandler(({ params }) => createResponse(gunzipSync(params.data).toString('utf-8')), undefined, 'Node: gz deflate.'); | ||
const handleRequestZlibInflate = RequestZlibInflate.createRequestHandler(({ params }) => createResponse(gunzipSync(arrayBufferViewToBuffer(params.data))), undefined, 'Node: gz deflate.'); | ||
const supportedFetchProtocols = { 'http:': true, 'https:': true }; | ||
@@ -73,7 +46,7 @@ /** | ||
*/ | ||
const handleRequestFsReadBinaryFileHttp = RequestFsReadBinaryFile.createRequestHandler((req, next) => { | ||
const handleRequestFsReadFileHttp = RequestFsReadFile.createRequestHandler((req, next) => { | ||
const { url } = req.params; | ||
if (!(url.protocol in supportedFetchProtocols)) | ||
return next(req); | ||
return createResponse(fetchURL(url).then((content) => ({ url, content }))); | ||
return createResponse(fetchURL(url).then((content) => CFileResource.from({ ...req.params, content }))); | ||
}, undefined, 'Node: Read Http(s) file.'); | ||
@@ -83,8 +56,9 @@ /** | ||
*/ | ||
const handleRequestFsReadBinaryFileSyncData = RequestFsReadBinaryFileSync.createRequestHandler((req, next) => { | ||
const { url } = req.params; | ||
const handleRequestFsReadFileSyncData = RequestFsReadFileSync.createRequestHandler((req, next) => { | ||
const { url, encoding } = req.params; | ||
if (url.protocol !== 'data:') | ||
return next(req); | ||
const data = decodeDataUrl(url); | ||
return createResponse({ url, content: data.data, baseFilename: data.attributes.get('filename') }); | ||
// console.error('handleRequestFsReadFileSyncData %o', { url, encoding, data }); | ||
return createResponse(CFileResource.from({ url, content: data.data, encoding, baseFilename: data.attributes.get('filename') })); | ||
}, undefined, 'Node: Read data: urls.'); | ||
@@ -94,7 +68,7 @@ /** | ||
*/ | ||
const handleRequestFsReadBinaryFileData = RequestFsReadBinaryFile.createRequestHandler((req, next, dispatcher) => { | ||
const handleRequestFsReadFileData = RequestFsReadFile.createRequestHandler((req, next, dispatcher) => { | ||
const { url } = req.params; | ||
if (url.protocol !== 'data:') | ||
return next(req); | ||
const res = dispatcher.dispatch(RequestFsReadBinaryFileSync.create(req.params)); | ||
const res = dispatcher.dispatch(RequestFsReadFileSync.create(req.params)); | ||
if (!isServiceResponseSuccess(res)) | ||
@@ -104,8 +78,2 @@ return res; | ||
}, undefined, 'Node: Read data: urls.'); | ||
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 }; | ||
} | ||
/** | ||
@@ -139,12 +107,47 @@ * Handle fs:stat | ||
*/ | ||
const handleRequestFsWriteFile = RequestFsWriteFile.createRequestHandler(({ params }) => createResponse(fs.writeFile(params.url, params.content)), undefined, 'Node: fs.writeFile'); | ||
const handleRequestFsWriteFile = RequestFsWriteFile.createRequestHandler(({ params }) => createResponse(writeFile(params, params.content)), undefined, 'Node: fs.writeFile'); | ||
async function writeFile(fileRef, content) { | ||
const gz = isGZipped(content); | ||
const { url, encoding, baseFilename } = fileRef; | ||
const resultRef = { url, encoding, baseFilename, gz }; | ||
await fs.writeFile(fileURLToPath(fileRef.url), encodeContent(fileRef, content)); | ||
return resultRef; | ||
} | ||
/** | ||
* Handle fs:writeFile | ||
*/ | ||
const handleRequestFsWriteFileDataUrl = RequestFsWriteFile.createRequestHandler((req, next) => { | ||
const fileResource = req.params; | ||
const { url } = req.params; | ||
if (url.protocol !== 'data:') | ||
return next(req); | ||
const gz = isGZipped(fileResource.content); | ||
const baseFilename = fileResource.baseFilename || 'file.txt' + (gz ? '.gz' : ''); | ||
const mt = guessMimeType(baseFilename); | ||
const mediaType = mt?.mimeType || 'text/plain'; | ||
const dataUrl = toDataUrl(fileResource.content, mediaType, [['filename', baseFilename]]); | ||
return createResponse(Promise.resolve({ url: dataUrl, baseFilename, gz, encoding: mt?.encoding })); | ||
}, undefined, 'Node: fs.writeFile DataUrl'); | ||
/** | ||
* Handle fs:writeFile compressed | ||
*/ | ||
const handleRequestFsWriteFileGz = RequestFsWriteFile.createRequestHandler((req, next) => { | ||
const { url, content } = req.params; | ||
if (!isGzFile(url)) | ||
const handleRequestFsWriteFileGz = RequestFsWriteFile.createRequestHandler((req, next, dispatcher) => { | ||
const fileResource = req.params; | ||
if (!fileResource.gz && | ||
!isGzFile(fileResource.url) && | ||
(!fileResource.baseFilename || !isGzFile(fileResource.baseFilename))) { | ||
return next(req); | ||
return createResponse(fs.writeFile(url, gzipSync(content))); | ||
}, undefined, 'Node: http get stat'); | ||
} | ||
if (typeof fileResource.content !== 'string' && isGZipped(fileResource.content)) { | ||
// Already compressed. | ||
return next(req); | ||
} | ||
return createResponse(compressAndChainWriteRequest(dispatcher, fileResource, fileResource.content)); | ||
}, undefined, 'Node: fs.writeFile compressed'); | ||
async function compressAndChainWriteRequest(dispatcher, fileRef, content) { | ||
const buf = await pGzip(encodeContent(fileRef, content)); | ||
const res = dispatcher.dispatch(RequestFsWriteFile.create({ ...fileRef, content: buf })); | ||
assert(isServiceResponseSuccess(res)); | ||
return res.value; | ||
} | ||
export function registerHandlers(serviceBus) { | ||
@@ -156,11 +159,10 @@ /** | ||
const handlers = [ | ||
handleRequestFsReadFile, | ||
handleRequestFsReadFileSync, | ||
handleRequestFsWriteFile, | ||
handleRequestFsWriteFileDataUrl, | ||
handleRequestFsWriteFileGz, | ||
handleRequestFsReadBinaryFile, | ||
handleRequestFsReadBinaryFileSync, | ||
handleRequestFsReadBinaryFileHttp, | ||
handleRequestFsReadBinaryFileData, | ||
handleRequestFsReadBinaryFileSyncData, | ||
handleRequestFsReadFile, | ||
handleRequestFsReadFileSync, | ||
handleRequestFsReadFileHttp, | ||
handleRequestFsReadFileData, | ||
handleRequestFsReadFileSyncData, | ||
handleRequestZlibInflate, | ||
@@ -173,2 +175,10 @@ handleRequestFsStatSync, | ||
} | ||
function encodeContent(ref, content) { | ||
if (typeof content === 'string') { | ||
if (!ref.encoding || ref.encoding === 'utf-8') | ||
return content; | ||
return arrayBufferViewToBuffer(encodeString(content, ref.encoding)); | ||
} | ||
return arrayBufferViewToBuffer(content); | ||
} | ||
//# sourceMappingURL=file.js.map |
export { toArray as asyncIterableToArray } from './async/asyncIterable.js'; | ||
export * from './common/index.js'; | ||
export type { CSpellIO } from './CSpellIO.js'; | ||
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js'; | ||
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js'; | ||
export type { BufferEncoding, TextEncoding } from './models/BufferEncoding.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 * from './common/index.js'; | ||
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js'; | ||
@@ -3,0 +4,0 @@ export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js'; |
@@ -1,2 +0,3 @@ | ||
export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'utf16be' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'binary' | 'latin1' | 'hex'; | ||
export type TextEncoding = 'utf-8' | 'utf8' | 'utf16le' | 'utf16be' | 'utf-16le' | 'utf-16be'; | ||
export type BufferEncoding = 'base64' | 'base64url' | 'hex' | TextEncoding; | ||
//# sourceMappingURL=BufferEncoding.d.ts.map |
@@ -6,15 +6,13 @@ import type { BufferEncoding } from './BufferEncoding.js'; | ||
*/ | ||
url: URL; | ||
} | ||
export interface FileResource extends FileReference { | ||
readonly url: URL; | ||
/** | ||
* The contents of the file | ||
*/ | ||
content: string | ArrayBufferView; | ||
/** | ||
* The filename of the file if known. | ||
* Useful for `data:` urls. | ||
*/ | ||
baseFilename?: string | undefined; | ||
readonly baseFilename?: string | undefined; | ||
/** | ||
* The encoding to use when reading the file. | ||
*/ | ||
readonly encoding?: BufferEncoding | undefined; | ||
/** | ||
* - `true` if the content had been gzip compressed. | ||
@@ -24,14 +22,15 @@ * - `false` if the content was NOT gzip compressed. | ||
*/ | ||
gz?: boolean; | ||
readonly gz?: boolean | undefined; | ||
} | ||
export interface TextFileResource extends FileResource { | ||
content: string; | ||
export interface FileResourceBase extends FileReference { | ||
/** | ||
* The encoding used to decode the file. | ||
* The contents of the file | ||
*/ | ||
encoding: BufferEncoding; | ||
readonly content: string | ArrayBufferView; | ||
} | ||
export interface BinaryFileResource extends FileResource { | ||
content: ArrayBufferView; | ||
export interface FileResource extends FileResourceBase { | ||
getText(): string; | ||
} | ||
export type UrlOrFilename = string | URL; | ||
export type UrlOrReference = UrlOrFilename | FileReference; | ||
//# sourceMappingURL=FileResource.d.ts.map |
@@ -12,4 +12,4 @@ /// <reference types="node" resolution-mode="require"/> | ||
*/ | ||
export declare function encodeDataUrl(data: string | Buffer, mediaType: string, attributes?: Iterable<readonly [string, string]> | undefined): string; | ||
export declare function toDataUrl(data: string | Buffer, mediaType: string, attributes?: Iterable<[string, string]> | undefined): URL; | ||
export declare function encodeDataUrl(data: string | Buffer | ArrayBufferView, mediaType: string, attributes?: Iterable<readonly [string, string]> | undefined): string; | ||
export declare function toDataUrl(data: string | Buffer | ArrayBufferView, mediaType: string, attributes?: Iterable<[string, string]> | undefined): URL; | ||
export interface DecodedDataUrl { | ||
@@ -16,0 +16,0 @@ data: Buffer; |
import { promises as fs } from 'fs'; | ||
import * as fsPath from 'path'; | ||
import { toURL } from './file/util.js'; | ||
import { arrayBufferViewToBuffer } from '../common/arrayBuffers.js'; | ||
import { toFileURL } from './file/url.js'; | ||
/** | ||
@@ -18,3 +19,4 @@ * Generates a string of the following format: | ||
const attribs = encodeAttributes(attributes || []); | ||
return `data:${mediaType}${attribs};base64,${data.toString('base64url')}`; | ||
const buf = arrayBufferViewToBuffer(data); | ||
return `data:${mediaType}${attribs};base64,${buf.toString('base64url')}`; | ||
} | ||
@@ -32,4 +34,4 @@ export function toDataUrl(data, mediaType, attributes) { | ||
// Ensure charset is first. | ||
const attribMap = new Map([['charset', 'utf8']].concat([...attributes])); | ||
attribMap.set('charset', 'utf8'); // Make sure it is always `utf8`. | ||
const attribMap = new Map([['charset', 'utf-8']].concat([...attributes])); | ||
attribMap.set('charset', 'utf-8'); // Make sure it is always `utf-8`. | ||
const attribs = encodeAttributes(attribMap); | ||
@@ -63,3 +65,3 @@ return `data:${mediaType}${attribs}${useBase64 ? ';base64' : ''},${encoded}`; | ||
export async function encodeDataUrlFromFile(path, mediaType, attributes) { | ||
const url = toURL(path); | ||
const url = toFileURL(path); | ||
const filename = fsPath.basename(url.pathname); | ||
@@ -80,2 +82,4 @@ const guess = guessMimeType(filename); | ||
return { mimeType: 'text/plain', encoding: 'utf-8' }; | ||
if (filename.endsWith('.txt.gz')) | ||
return { mimeType: 'application/gzip' }; | ||
if (filename.endsWith('.gz')) | ||
@@ -82,0 +86,0 @@ return { mimeType: 'application/gzip' }; |
@@ -1,2 +0,3 @@ | ||
import { FetchUrlError, isError } from './FetchError.js'; | ||
import { _fetch as fetch } from './_fetch.js'; | ||
import { FetchUrlError, toFetchUrlError } from './FetchError.js'; | ||
export async function fetchHead(request) { | ||
@@ -9,7 +10,3 @@ const url = toURL(request); | ||
catch (e) { | ||
console.warn('fetchHead Error %o', e); | ||
if (isError(e)) { | ||
throw FetchUrlError.fromError(url, e); | ||
} | ||
throw e; | ||
throw toFetchUrlError(e, url); | ||
} | ||
@@ -26,9 +23,3 @@ } | ||
catch (e) { | ||
// console.warn('fetchURL Error %o', e); | ||
if (e instanceof FetchUrlError) | ||
throw e; | ||
if (isError(e)) { | ||
throw FetchUrlError.fromError(url, e); | ||
} | ||
throw e; | ||
throw toFetchUrlError(e, url); | ||
} | ||
@@ -35,0 +26,0 @@ } |
@@ -17,3 +17,5 @@ /// <reference types="node" resolution-mode="require"/> | ||
export declare function getCause(e: unknown): NodeJS.ErrnoException | undefined; | ||
export declare function toFetchUrlError(err: unknown, url: URL): FetchUrlError; | ||
export declare function toError(err: unknown): Error; | ||
export {}; | ||
//# sourceMappingURL=FetchError.d.ts.map |
@@ -41,3 +41,3 @@ export class FetchUrlError extends Error { | ||
export function isErrorWithOptionalCause(e) { | ||
return !!e && typeof e === 'object' && 'cause' in e && isNodeError(e.cause); | ||
return isError(e) && (!('cause' in e) || isNodeError(e.cause) || isNodeError(e)); | ||
} | ||
@@ -47,2 +47,8 @@ export function getCause(e) { | ||
} | ||
export function toFetchUrlError(err, url) { | ||
return err instanceof FetchUrlError ? err : FetchUrlError.fromError(url, toError(err)); | ||
} | ||
export function toError(err) { | ||
return err instanceof Error ? err : Error('Unknown Error', { cause: err }); | ||
} | ||
//# sourceMappingURL=FetchError.js.map |
@@ -1,4 +0,3 @@ | ||
export { readFileText, readFileTextSync } from './fileReader.js'; | ||
export { writeToFile, writeToFileIterable } from './fileWriter.js'; | ||
export { getStat, getStatSync } from './stat.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,4 +0,3 @@ | ||
export { readFileText, readFileTextSync } from './fileReader.js'; | ||
export { writeToFile, writeToFileIterable } from './fileWriter.js'; | ||
export { getStat, getStatSync } from './stat.js'; | ||
//# sourceMappingURL=index.js.map |
import { promises as fs, statSync } from 'fs'; | ||
import { format } from 'util'; | ||
import { fetchHead } from './fetch.js'; | ||
import { isFileURL, isUrlLike, toURL } from './util.js'; | ||
import { isFileURL, isUrlLike, toFileURL } from './url.js'; | ||
export async function getStat(filenameOrUri) { | ||
if (isUrlLike(filenameOrUri)) { | ||
const url = toURL(filenameOrUri); | ||
const url = toFileURL(filenameOrUri); | ||
if (!isFileURL(url)) { | ||
@@ -9,0 +9,0 @@ try { |
@@ -1,3 +0,2 @@ | ||
export { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync } from './RequestFsReadBinaryFile.js'; | ||
export { RequestFsReadFileText as RequestFsReadFile } from './RequestFsReadFile.js'; | ||
export { RequestFsReadFile as RequestFsReadFile } from './RequestFsReadFile.js'; | ||
export { RequestFsReadFileTextSync as RequestFsReadFileSync } from './RequestFsReadFileSync.js'; | ||
@@ -4,0 +3,0 @@ export { RequestFsStat, RequestFsStatSync } from './RequestFsStat.js'; |
@@ -1,3 +0,2 @@ | ||
export { RequestFsReadBinaryFile, RequestFsReadBinaryFileSync } from './RequestFsReadBinaryFile.js'; | ||
export { RequestFsReadFileText as RequestFsReadFile } from './RequestFsReadFile.js'; | ||
export { RequestFsReadFile as RequestFsReadFile } from './RequestFsReadFile.js'; | ||
export { RequestFsReadFileTextSync as RequestFsReadFileSync } from './RequestFsReadFileSync.js'; | ||
@@ -4,0 +3,0 @@ export { RequestFsStat, RequestFsStatSync } from './RequestFsStat.js'; |
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus'; | ||
import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
import type { TextFileResource } from '../models/FileResource.js'; | ||
import type { FileResource } from '../models/FileResource.js'; | ||
interface RequestParams { | ||
readonly url: URL; | ||
readonly encoding: BufferEncoding; | ||
readonly encoding?: BufferEncoding | undefined; | ||
} | ||
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 declare const RequestFsReadFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<FileResource>>, RequestParams, "fs:readFile">; | ||
export type RequestFsReadFile = ServiceRequestFactoryRequestType<typeof RequestFsReadFile>; | ||
export {}; | ||
//# sourceMappingURL=RequestFsReadFile.d.ts.map |
import { requestFactory } from '@cspell/cspell-service-bus'; | ||
const RequestType = 'fs:readFile'; | ||
export const RequestFsReadFileText = requestFactory(RequestType); | ||
export const RequestFsReadFile = requestFactory(RequestType); | ||
//# sourceMappingURL=RequestFsReadFile.js.map |
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus'; | ||
import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
import type { TextFileResource } from '../models/FileResource.js'; | ||
import type { FileResource } from '../models/FileResource.js'; | ||
interface RequestParams { | ||
readonly url: URL; | ||
readonly encoding: BufferEncoding; | ||
readonly encoding?: BufferEncoding | undefined; | ||
} | ||
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, TextFileResource>, RequestParams, "fs:readFileSync">; | ||
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, FileResource>, RequestParams, "fs:readFileSync">; | ||
export type RequestFsReadFileTextSync = ServiceRequestFactoryRequestType<typeof RequestFsReadFileTextSync>; | ||
export {}; | ||
//# sourceMappingURL=RequestFsReadFileSync.d.ts.map |
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus'; | ||
interface RequestParams { | ||
readonly url: URL; | ||
readonly content: string; | ||
import type { FileReference } from '../models/FileResource.js'; | ||
interface RequestParams extends FileReference { | ||
readonly content: string | ArrayBufferView; | ||
} | ||
export declare const RequestFsWriteFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:writeFile", RequestParams, Promise<void>>, RequestParams, "fs:writeFile">; | ||
export declare const RequestFsWriteFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:writeFile", RequestParams, Promise<FileReference>>, RequestParams, "fs:writeFile">; | ||
export type RequestFsWriteFile = ServiceRequestFactoryRequestType<typeof RequestFsWriteFile>; | ||
export {}; | ||
//# sourceMappingURL=RequestFsWriteFile.d.ts.map |
@@ -1,9 +0,8 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus'; | ||
interface RequestParams { | ||
readonly data: Buffer; | ||
readonly data: ArrayBufferView; | ||
} | ||
export declare const RequestZlibInflate: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"zlib:inflate", RequestParams, string>, RequestParams, "zlib:inflate">; | ||
export declare const RequestZlibInflate: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"zlib:inflate", RequestParams, ArrayBufferView>, RequestParams, "zlib:inflate">; | ||
export type RequestZlibInflate = ServiceRequestFactoryRequestType<typeof RequestZlibInflate>; | ||
export {}; | ||
//# sourceMappingURL=RequestZlibInflate.d.ts.map |
{ | ||
"name": "cspell-io", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"description": "A library of useful I/O functions used across various cspell tools.", | ||
@@ -50,8 +50,8 @@ "type": "module", | ||
"lorem-ipsum": "^2.0.8", | ||
"typescript": "^5.2.2" | ||
"typescript": "^5.3.2" | ||
}, | ||
"dependencies": { | ||
"@cspell/cspell-service-bus": "8.0.0" | ||
"@cspell/cspell-service-bus": "8.1.0" | ||
}, | ||
"gitHead": "67c22bf98baed1c17bbc658fba8656262d17e370" | ||
"gitHead": "28568808deaf39b9ffa71fd0f722441ff1b8c794" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73007
81
1642
5
+ Added@cspell/cspell-service-bus@8.1.0(transitive)
- Removed@cspell/cspell-service-bus@8.0.0(transitive)