本文整理匯總了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();
});