本文整理汇总了TypeScript中fs.access函数的典型用法代码示例。如果您正苦于以下问题:TypeScript access函数的具体用法?TypeScript access怎么用?TypeScript access使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了access函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: next
({ parseAscii, parseNative }: {
parseAscii: boolean;
parseNative: boolean;
}, next: NodeBack) => {
// initialise ascii flag
parse.setOptions({
ascii: parseAscii,
native: parseNative,
});
// always build on startup if in dev mode
if (nconf.any('build_emoji', 'BUILD_EMOJI')) {
next(null, true);
return;
}
// otherwise, build if never built before
access(tableFile, (err) => {
if (err && err.code !== 'ENOENT') {
next(err);
return;
}
next(null, !!err);
});
},
示例2: cacheAndDeliver
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
// Local variables
let lookup = path.basename(decodeURI(req.url)) || 'index.html';
let filePath = `${__dirname}/../content/${lookup}`
// fs.exists had deprecated. Please use fs.stat() or fs.access()
fs.access(filePath, (err: NodeJS.ErrnoException) => {
// Check file
console.log(err ? `${filePath} doesn't exist` : `${filePath} is there`);
// Response with 404
if (Boolean(err)) {
res.writeHead(404);
res.end('Page not Found!');
return;
}
// Read file when existed
cacheAndDeliver(filePath, (err: NodeJS.ErrnoException, data: Buffer) => {
// Content not found
if (err) { res.writeHead(500); res.end('ServerError!'); return; }
// Content can be found
let headers = { 'Content-type': mimeTypes[path.extname(lookup)] };
res.writeHead(200, headers);
res.end(data);
});
});
}).listen(8080, () => {
示例3: test
test('should create the JSON File', done => {
fs.access(testFile1 + ".json", fs.constants.R_OK, function (err) {
expect(err).toBeNull()
done()
})
})
示例4: access
return new Promise<boolean>(resolve => {
access(path, err => {
const pathExists = !err;
resolve(pathExists);
});
});
示例5: Promise
return new Promise(resolve => {
access(path, e => {
// A path exists if there is no error
const pathExists = !e;
resolve(pathExists);
});
});
示例6: Promise
return new Promise(resolve => {
const dir = path.resolve(__dirname, `../src/topics/${topic}`)
fs.access(dir, fs.constants.F_OK, async err => {
if (err) return resolve(false)
return resolve(true)
})
})
示例7: Promise
return new Promise((resolve, reject) => {
fs.access(file, fs.constants.W_OK, (err) => {
if (err) {
resolve(false);
}
resolve(true);
});
});
示例8: Promise
return new Promise((resolve, reject) => {
fs.access(folder, fs.constants.W_OK, (err) => {
if (err) {
reject({message: 'Error during getting write access to temp folder', error: err.toString()});
}
});
resolve();
});