本文整理汇总了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);
}