How to use the mz/fs.access function in mz

To help you get started, we’ve selected a few mz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jakoblo / ufo / src / js / filesystem / write / fs-write-utils.js View on Github external
return new Promise( function(resolve, reject) {
    fs.access(source, sourcePermissions) // Can Read Source? 
      .then( () => {
          fs.access(nodePath.dirname(destination), fs.constants.W_OK)  // Can Write Target Parent?
            .then( () => {
              fs.access(destination, fs.constants.W_OK) // does the Target already exists?
                .then( () => {
                  debugger
                  if(clobber) {
                    resolve() // im allowed to overwrite the existing destionation
                  } else {
                    console.log('reject')
                    reject({  // not allowed to overwrite
                      code: c.ERROR_DEST_ALREADY_EXISTS
                    })
                  }
                })
                .catch((err) => {
github jakoblo / ufo / src / js / filesystem / write / fs-write-utils.js View on Github external
.then( () => {
          fs.access(nodePath.dirname(destination), fs.constants.W_OK)  // Can Write Target Parent?
            .then( () => {
              fs.access(destination, fs.constants.W_OK) // does the Target already exists?
                .then( () => {
                  debugger
                  if(clobber) {
                    resolve() // im allowed to overwrite the existing destionation
                  } else {
                    console.log('reject')
                    reject({  // not allowed to overwrite
                      code: c.ERROR_DEST_ALREADY_EXISTS
                    })
                  }
                })
                .catch((err) => {
                  if(err.code == c.ERROR_NOT_EXISTS) 
                  { resolve() } // Destination does not exists -> free space -> go
github InfiniteLibrary / infinite-electron / app / streamer / index.js View on Github external
resolveEpub(id, url) {
    const bookPath = path.join(this.repo, id);
    return fs.access(bookPath, fs.constants.R_OK)
      .then(
        () => bookPath,
        // If the book doesn't exist, download it:
        () => this.downloadEpub(bookPath, url)
      );
  }
github d6u / web-playground / src / util / AssetUtil.js View on Github external
const getPathForAsset = curryN(3, wrap(function *(type, dir, config) {
  const exts = extensionsForAsset(type, config);
  for (const ext of exts) {
    const fpath = join(dir, `${type}.${ext}`);
    try {
      yield access(fpath, R_OK);
    } catch (err) {
      continue;
    }
    return fpath;
  }
  return null;
}));
github andywer / gear / src / commands / type-check.js View on Github external
async function exists (path) {
  try {
    await fs.access(path)
    return true
  } catch (error) {
    return false
  }
}
github d6u / web-playground / src / util / FileUtil.js View on Github external
export const readAsset = wrap(function *(name) {
  const fpath = getAssetPath(name);
  try {
    yield access(fpath, R_OK);
    return yield readToStr(fpath);
  } catch (err) {
    return null;
  }
});
github ETCDEVTeam / emerald-js / src / download / downloader.js View on Github external
return new Promise((resolve, reject) => {
      fs.access(this.basedir, (accessError) => {
        if (accessError) {
          fs.mkdir(this.basedir, 0o777, (error) => {
            if (error) {
              reject(error);
            } else {
              resolve(x);
            }
          });
        } else {
          resolve(x);
        }
      });
    });
  }
github erzu / porter / packages / porter / src / module.js View on Github external
async _addCache() {
    const fpath = path.join(this.package.app.cache.dest, this.id)
    const dir = path.dirname(fpath)

    try {
      await access(dir)
    } catch (err) {
      await mkdirp(dir)
    }

    await writeFile(`${fpath}.cache`, JSON.stringify(this.cache))
  }