How to use the accessAsync function from fs-extra

Find comprehensive JavaScript fs-extra.accessAsync code examples handpicked from public code repositorys.

93
94
95
96
97
98
99
100
101
102
const downloadAsync = async (url, destDir, filename = path.basename(url), description) => {
  log(`Downloading ${description} from ${url}`)
  await fs.ensureDirAsync(destDir)
  const destPath = path.join(destDir, filename)
  try {
    await fs.accessAsync(destPath, fs.R_OK)
    log(`Use existing ${destPath}`)
  }catch (e) {
    const [response, body] = await requestAsync({
      url: url,
fork icon356
star icon0
watch icon1

16
17
18
19
20
21
22
23
24
25
const referencePath = opts.refPath;
const currentPath = temp.path({suffix: '.png'});

return capture.image.save(currentPath)
    .then(() => {
        return fs.accessAsync(referencePath)
            .catch(
                () => Promise.reject(new NoRefImageError(referencePath, currentPath))
            );
    })
fork icon164
star icon0
watch icon152

61
62
63
64
65
66
67
68
69
70
    .reduce((a, b) => a || b);
}

async function exists(pathname) {
  try {
    await fs.accessAsync(pathname);
    return true;
  } catch (error) {
    return false;
  }
fork icon36
star icon0
watch icon2

184
185
186
187
188
189
190
191
192
193
 * Replace exceptions from fs.access with IgnorableError
 * @param filename
 * @returns {Promise.<undefined>|*}
 */
fileAccessable(filename) {
  return Fse.accessAsync(filename, Fse.constants.R_OK)
    .then(BbPromise.resolve,
      (err) => {
        if (process.env.SLS_DEBUG) {
          this.log(err.stack);
fork icon16
star icon25
watch icon3

134
135
136
137
138
139
140
141
142
143
}

getSizeFromLocal(src) {
  // make sure the image exists, then get its size
  const filepath = path.resolve(this.tplPath, src)
  return fse.accessAsync(filepath, fse.F_OK).then(() => {
    this.copyLocalImgToBuild(src)
    return sizeOf(filepath)
  })
}
fork icon1
star icon16
watch icon9

9
10
11
12
13
14
15
16
17
18
module.exports = Promise.mapSeries([
  /**
   * SimpleMDE
   */
  () => {
    return fs.accessAsync('./assets/js/simplemde').then(() => {
      console.info(colors.white('  └── ') + colors.magenta('SimpleMDE directory already exists. Task aborted.'))
      return true
    }).catch(err => {
      if (err.code === 'ENOENT') {
fork icon0
star icon1
watch icon4

+ 3 other calls in file

101
102
103
104
105
106
107
108
109
110
Cache.prototype.getAll = function () {
    return this._cache;
};

Cache.prototype.isProfileCached = function (profile) {
    return fs.accessAsync(path.join(this._options.cachePath, profile), fs.constants.F_OK).then(() => {
        return Promise.resolve(true);
    }).catch((err) => {
        return Promise.resolve(false);
    })
fork icon0
star icon1
watch icon1

73
74
75
76
77
78
79
80
81
82
const downloadAsync = async (url, destDir, filename = path.basename(url), description) => {
  log(`Downloading ${description} from ${url}`);
  await fs.ensureDirAsync(destDir);
  const destPath = path.join(destDir, filename);
  try {
    await fs.accessAsync(destPath, fs.R_OK);
    log(`Use existing ${destPath}`);
  } catch (e) {
    const [response, body] = await requestAsync({
      url,
fork icon0
star icon0
watch icon2

+ 3 other calls in file

11
12
13
14
15
16
17
18
19
20
module.exports = function deleteMeta(req, res, next) {
  let fs_id = req.params.fs_id
  let meta_id = req.params.meta_id
  let target = path.resolve(path.join(storage_path, fs_id, `${meta_id}_meta`))

  fs.accessAsync(target, fs.F_OK)
  .then( () => {
    return fs.unlinkAsync(target)
  })
  .then( () => {
fork icon0
star icon0
watch icon3

94
95
96
97
98
99
100
101
102
103

debug('appPath %s', appPath)
debug('dest path %s', dest)

// make sure this path exists!
return fs.accessAsync(appPath)
.then(() => {
  debug('appPath exists %s', appPath)

  // clear out the existing symlink
fork icon0
star icon0
watch icon0

66
67
68
69
70
71
72
73
74
75
      ora.text = 'Wiki.js npm dependencies installed successfully.'
      resolve(true)
    })
  })
}).then(() => {
  fs.accessAsync(path.join(installDir, 'config.yml')).then(() => {
    /**
     * Upgrade mode
     */
    return new Promise((resolve, reject) => {
fork icon0
star icon0
watch icon2

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)