silverwolf-x/project / packages /next /src /lib /file-exists.ts
silverwolf-x's picture
download
raw
691 Bytes
import { existsSync, promises } from 'fs'
import isError from './is-error'
export enum FileType {
File = 'file',
Directory = 'directory',
}
export async function fileExists(
fileName: string,
type?: FileType
): Promise<boolean> {
try {
if (type === FileType.File) {
const stats = await promises.stat(fileName)
return stats.isFile()
} else if (type === FileType.Directory) {
const stats = await promises.stat(fileName)
return stats.isDirectory()
}
return existsSync(fileName)
} catch (err) {
if (
isError(err) &&
(err.code === 'ENOENT' || err.code === 'ENAMETOOLONG')
) {
return false
}
throw err
}
}

Xet Storage Details

Size:
691 Bytes
·
Xet hash:
cbdd7448ecbb4c80ccc7859fd29210217d449264b94963f2a0e53c68b4828a01

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.