Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cspell-io

Package Overview
Dependencies
Maintainers
1
Versions
278
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 8.2.1 to 8.2.3

4

dist/esm/common/CFileResource.d.ts

@@ -12,3 +12,3 @@ import type { BufferEncoding } from '../models/BufferEncoding.js';

get gz(): boolean;
getText(): string;
getText(encoding?: BufferEncoding): string;
toJson(): {

@@ -27,4 +27,4 @@ url: string;

}
export declare function fromFileResource(fileResource: FileResource): TextFileResource;
export declare function fromFileResource(fileResource: FileResource, encoding?: BufferEncoding): TextFileResource;
export declare function renameFileResource(fileResource: FileResource, url: URL): FileResource;
//# sourceMappingURL=CFileResource.d.ts.map

@@ -26,6 +26,6 @@ import { assert } from '../errors/assert.js';

}
getText() {
getText(encoding) {
if (this._text !== undefined)
return this._text;
const text = typeof this.content === 'string' ? this.content : decode(this.content, this.encoding);
const text = typeof this.content === 'string' ? this.content : decode(this.content, encoding ?? this.encoding);
this._text = text;

@@ -67,8 +67,8 @@ return text;

}
export function fromFileResource(fileResource) {
return CFileResource.from(fileResource);
export function fromFileResource(fileResource, encoding) {
return CFileResource.from(encoding ? { ...fileResource, encoding } : fileResource);
}
export function renameFileResource(fileResource, url) {
return CFileResource.from(url, fileResource.content, fileResource.encoding, fileResource.baseFilename, fileResource.gz);
return CFileResource.from({ ...fileResource, url });
}
//# sourceMappingURL=CFileResource.js.map
export { CFileReference, renameFileReference } from './CFileReference.js';
export { CFileResource, fromFileResource as createTextFileResource, renameFileResource } from './CFileResource.js';
export { compareStats } from './stat.js';
export { urlOrReferenceToUrl } from './urlOrReferenceToUrl.js';
//# sourceMappingURL=index.d.ts.map
export { CFileReference, renameFileReference } from './CFileReference.js';
export { CFileResource, fromFileResource as createTextFileResource, renameFileResource } from './CFileResource.js';
export { compareStats } from './stat.js';
export { urlOrReferenceToUrl } from './urlOrReferenceToUrl.js';
//# sourceMappingURL=index.js.map
export { toArray as asyncIterableToArray } from './async/asyncIterable.js';
export * from './common/index.js';
export { createTextFileResource } from './common/index.js';
export { compareStats, createTextFileResource } from './common/index.js';
export type { CSpellIO } from './CSpellIO.js';

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

export { toArray as asyncIterableToArray } from './async/asyncIterable.js';
export * from './common/index.js';
export { createTextFileResource } from './common/index.js';
export { compareStats, createTextFileResource } from './common/index.js';
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js';

@@ -5,0 +5,0 @@ export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';

@@ -30,3 +30,9 @@ import type { BufferEncoding } from './BufferEncoding.js';

export interface TextFileResource extends FileResource {
getText(): string;
/**
* Extract the text of the file.
* @param encoding - optional encoding to use when decoding the content.
* by default it uses the encoding of the file if one was specified, otherwise it uses `utf8`.
* If the content is a string, then the encoding is ignored.
*/
getText(encoding?: BufferEncoding): string;
}

@@ -33,0 +39,0 @@ export type UrlOrFilename = string | URL;

import type { CSpellIO } from './CSpellIO.js';
import { type DirEntry, type Disposable, type FileReference, type FileResource, type Stats } from './models/index.js';
import type { BufferEncoding, DirEntry, Disposable, FileReference, FileResource, Stats, TextFileResource } from './models/index.js';
type UrlOrReference = URL | FileReference;

@@ -19,2 +19,7 @@ type NextProvider = (url: URL) => VProviderFileSystem | undefined;

reset(): void;
/**
* Indicates that logging has been enabled.
*/
loggingEnabled: boolean;
enableLogging(value?: boolean): void;
}

@@ -34,6 +39,33 @@ export declare enum FSCapabilityFlags {

}
interface FileSystemBase {
readFile(url: UrlOrReference): Promise<FileResource>;
export interface VFileSystem {
/**
* Read a file.
* @param url - URL to read
* @param encoding - optional encoding
* @returns A FileResource, the content will not be decoded. Use `.getText()` to get the decoded text.
*/
readFile(url: UrlOrReference, encoding?: BufferEncoding): Promise<TextFileResource>;
/**
* Write a file
* @param file - the file to write
*/
writeFile(file: FileResource): Promise<FileReference>;
/**
* Get the stats for a url.
* @param url - Url to fetch stats for.
*/
stat(url: UrlOrReference): Promise<VfsStat>;
/**
* Read the directory entries for a url.
* The url should end with `/` to indicate a directory.
* @param url - the url to read the directory entries for.
*/
readDirectory(url: URL): Promise<VfsDirEntry[]>;
/**
* Get the capabilities for a URL.
* The capabilities can be more restrictive than the general capabilities of the provider.
* @param url - the url to try
*/
getCapabilities(url: URL): FSCapabilities;
/**
* Information about the provider.

@@ -43,10 +75,15 @@ * It is up to the provider to define what information is available.

providerInfo: FileSystemProviderInfo;
}
export interface VFileSystem extends FileSystemBase {
stat(url: UrlOrReference): Promise<VfsStat>;
readDirectory(url: URL): Promise<VfsDirEntry[]>;
getCapabilities(url: URL): FSCapabilities;
/**
* Indicates that a provider was found for the url.
*/
hasProvider: boolean;
}
export interface VProviderFileSystem extends FileSystemBase, Disposable {
export interface VProviderFileSystem extends Disposable {
readFile(url: UrlOrReference): Promise<FileResource>;
writeFile(file: FileResource): Promise<FileReference>;
/**
* Information about the provider.
* It is up to the provider to define what information is available.
*/
providerInfo: FileSystemProviderInfo;
stat(url: UrlOrReference): Stats | Promise<Stats>;

@@ -53,0 +90,0 @@ readDirectory(url: URL): Promise<DirEntry[]>;

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

import { urlOrReferenceToUrl } from './common/index.js';
import { createTextFileResource, urlOrReferenceToUrl } from './common/index.js';
import { getDefaultCSpellIO } from './CSpellIONode.js';
import { FileType, } from './models/index.js';
import { FileType } from './models/index.js';
const debug = false;
export var FSCapabilityFlags;

@@ -20,5 +21,17 @@ (function (FSCapabilityFlags) {

fs;
loggingEnabled = debug;
constructor() {
this.fs = fsPassThrough((url) => this._getFS(url));
}
enableLogging(value) {
this.loggingEnabled = value ?? true;
}
log = console.log;
logEvent = (event) => {
if (this.loggingEnabled) {
const id = event.traceID.toFixed(13).replace(/\d{4}(?=\d)/g, '$&.');
const msg = event.message ? `\n\t\t${event.message}` : '';
this.log(`${event.method}-${event.event}\t ID:${id} ts:${event.ts.toFixed(13)} ${chopUrl(event.url)}${msg}`);
}
};
registerFileSystemProvider(...providers) {

@@ -71,3 +84,3 @@ providers.forEach((provider) => this.providers.add(provider));

}
const fs = new WrappedProviderFs(next(url));
const fs = new WrappedProviderFs(next(url), this.logEvent);
this.cachedFs.set(key, fs);

@@ -216,2 +229,3 @@ return fs;

fs;
eventLogger;
hasProvider;

@@ -221,4 +235,5 @@ capabilities;

_capabilities;
constructor(fs) {
constructor(fs, eventLogger) {
this.fs = fs;
this.eventLogger = eventLogger;
this.hasProvider = !!fs;

@@ -229,2 +244,5 @@ this.capabilities = fs?.capabilities || FSCapabilityFlags.None;

}
logEvent(method, event, traceID, url, message) {
this.eventLogger({ method, event, url, traceID, ts: performance.now(), message });
}
getCapabilities(url) {

@@ -235,21 +253,37 @@ if (this.fs?.getCapabilities)

}
async stat(url) {
async stat(urlRef) {
const traceID = performance.now();
const url = urlOrReferenceToUrl(urlRef);
this.logEvent('stat', 'start', traceID, url);
try {
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Stat, 'stat', urlOrReferenceToUrl(url));
return new CVfsStat(await this.fs.stat(url));
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Stat, 'stat', url);
return new CVfsStat(await this.fs.stat(urlRef));
}
catch (e) {
this.logEvent('stat', 'error', traceID, url, e instanceof Error ? e.message : '');
throw wrapError(e);
}
finally {
this.logEvent('stat', 'end', traceID, url);
}
}
async readFile(url) {
async readFile(urlRef, encoding) {
const traceID = performance.now();
const url = urlOrReferenceToUrl(urlRef);
this.logEvent('readFile', 'start', traceID, url);
try {
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Read, 'readFile', urlOrReferenceToUrl(url));
return await this.fs.readFile(url);
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Read, 'readFile', url);
return createTextFileResource(await this.fs.readFile(urlRef), encoding);
}
catch (e) {
this.logEvent('readFile', 'error', traceID, url, e instanceof Error ? e.message : '');
throw wrapError(e);
}
finally {
this.logEvent('readFile', 'end', traceID, url);
}
}
async readDirectory(url) {
const traceID = performance.now();
this.logEvent('readDir', 'start', traceID, url);
try {

@@ -260,6 +294,13 @@ checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.ReadDir, 'readDirectory', url);

catch (e) {
this.logEvent('readDir', 'error', traceID, url, e instanceof Error ? e.message : '');
throw wrapError(e);
}
finally {
this.logEvent('readDir', 'end', traceID, url);
}
}
async writeFile(file) {
const traceID = performance.now();
const url = file.url;
this.logEvent('writeFile', 'start', traceID, url);
try {

@@ -270,4 +311,8 @@ checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Write, 'writeFile', file.url);

catch (e) {
this.logEvent('writeFile', 'error', traceID, url, e instanceof Error ? e.message : '');
throw wrapError(e);
}
finally {
this.logEvent('writeFile', 'end', traceID, url);
}
}

@@ -334,2 +379,14 @@ static disposeOf(fs) {

}
function chopUrl(url) {
if (!url)
return '';
const href = url.href;
const parts = href.split('/');
const n = parts.indexOf('node_modules');
if (n > 0) {
const tail = parts.slice(Math.max(parts.length - 3, n + 1));
return parts.slice(0, n + 1).join('/') + '/.../' + tail.join('/');
}
return href;
}
//# sourceMappingURL=VirtualFS.js.map
{
"name": "cspell-io",
"version": "8.2.1",
"version": "8.2.3",
"description": "A library of useful I/O functions used across various cspell tools.",

@@ -54,5 +54,5 @@ "type": "module",

"dependencies": {
"@cspell/cspell-service-bus": "8.2.1"
"@cspell/cspell-service-bus": "8.2.3"
},
"gitHead": "b0c889ee4068aa8a2447106c5c7f449debc85bdd"
"gitHead": "e3098b21e0a199d61226f8ff4989d48b385eddfa"
}
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