Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use CSpellIO as the default file read layer. (#3323)
* feat: Use CSpellIO as the default file read layer. * Update BufferEncoding.ts * fix: use `fileURLToPath` to workaround yarn bug
- Loading branch information
Showing
6 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { getDefaultCSpellIO } from '../CSpellIONode'; | ||
import { toError } from '../errors'; | ||
import { Stats } from '../models'; | ||
import type { BufferEncoding } from '../models/BufferEncoding'; | ||
import type { | ||
getStat as GetStatFn, | ||
getStatSync as GetStatSyncFn, | ||
readFile as ReadFileFn, | ||
readFileSync as ReadFileSyncFn, | ||
} from '../node/file'; | ||
|
||
export const readFile: typeof ReadFileFn = function ( | ||
filename: string | URL, | ||
encoding?: BufferEncoding | ||
): Promise<string> { | ||
return getDefaultCSpellIO() | ||
.readFile(filename, encoding) | ||
.then((fr) => fr.content); | ||
}; | ||
|
||
export const readFileSync: typeof ReadFileSyncFn = function ( | ||
filename: string | URL, | ||
encoding?: BufferEncoding | ||
): string { | ||
return getDefaultCSpellIO().readFileSync(filename, encoding).content; | ||
}; | ||
|
||
export const getStat: typeof GetStatFn = function (filenameOrUri: string): Promise<Stats | Error> { | ||
return getDefaultCSpellIO() | ||
.getStat(filenameOrUri) | ||
.catch((e) => toError(e)); | ||
}; | ||
|
||
export const getStatSync: typeof GetStatSyncFn = function (filenameOrUri: string): Stats | Error { | ||
try { | ||
return getDefaultCSpellIO().getStatSync(filenameOrUri); | ||
} catch (e) { | ||
return toError(e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export { readFile, readFileSync } from './../node/file'; | ||
export { writeToFile, writeToFileIterable, writeToFileIterableP } from './../node/file'; | ||
export { getStat, getStatSync } from './../node/file'; | ||
export { getStat, getStatSync, readFile, readFileSync } from './file'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ export type BufferEncoding = | |
| 'ucs-2' | ||
| 'base64' | ||
| 'base64url' | ||
| 'binary' | ||
| 'latin1' | ||
| 'hex'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters