本文整理匯總了TypeScript中isbinaryfile.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: readTextFile
export function readTextFile(filename: string, encoding: string, callback: (err: Error | null, res?: string) => void) {
if (typeof encoding === "function") {
callback = encoding;
encoding = "utf-8";
} else if (typeof encoding !== "string") {
throw new TypeError("encoding must be a string");
} else if (!isEncodingSupported(encoding)) {
throw new TypeError("encoding is not supported: " + encoding);
}
// isbinaryfile check first because it checks first 1000 bytes of a file
// so we don't load whole file if it's binary
isbinaryfile(filename, function (err: Error, isBinary: boolean) {
if (err) {
return callback(err);
}
if (isBinary) {
const err2: NodeJS.ErrnoException = new Error("ECHARSET: file is a binary file: " + filename);
err2.code = "ECHARSET";
return callback(err2);
}
fs.readFile(filename, encoding, function (err2, content) {
if (err2) {
return callback(err2);
}
content = stripBom(content);
// \uFFFD is used to replace an incoming character
// whose value is unknown or unrepresentable
if (/\uFFFD/.test(content)) {
const err3: NodeJS.ErrnoException = new Error("ECHARSET: unsupported encoding in file: " + filename);
err3.code = "ECHARSET";
return callback(err3);
}
callback(null, content);
});
});
}
示例2: isBinaryFileSync
export function isBinaryFileSync(filename: string): boolean {
return isbinaryfile(filename);
}
示例3: isBinaryFile
export function isBinaryFile(filename: string, callback: (err?: Error, res?: boolean) => void) {
isbinaryfile(filename, callback);
}