CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
fs.js63 linesDownload Raw Back to mz
1 2var Promise = require('any-promise')3var fs4try {5  fs = require('graceful-fs')6} catch(err) {7  fs = require('fs')8}9 10var api = [11  'appendFile',12  'chmod',13  'chown',14  'close',15  'fchmod',16  'fchown',17  'fdatasync',18  'fstat',19  'fsync',20  'ftruncate',21  'futimes',22  'lchown',23  'link',24  'lstat',25  'mkdir',26  'open',27  'read',28  'readFile',29  'readdir',30  'readlink',31  'realpath',32  'rename',33  'rmdir',34  'stat',35  'symlink',36  'truncate',37  'unlink',38  'utimes',39  'write',40  'writeFile'41]42 43typeof fs.access === 'function' && api.push('access')44typeof fs.copyFile === 'function' && api.push('copyFile')45typeof fs.mkdtemp === 'function' && api.push('mkdtemp')46 47require('thenify-all').withCallback(fs, exports, api)48 49exports.exists = function (filename, callback) {50  // callback51  if (typeof callback === 'function') {52    return fs.stat(filename, function (err) {53      callback(null, !err);54    })55  }56  // or promise57  return new Promise(function (resolve) {58    fs.stat(filename, function (err) {59      resolve(!err)60    })61  })62}63