fs#stat JavaScript Examples

The following examples show how to use fs#stat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: compress.js    From ucompress with ISC License 6 votes vote down vote up
br = (source, mode) => new Promise((res, rej) => {
  const dest = source + '.br';
  stat(source, (err, stats) => {
    /* istanbul ignore next */
    if (err) rej(err);
    else pipeline(
      createReadStream(source),
      createBrotliCompress({
        [BROTLI_PARAM_SIZE_HINT]: stats.size,
        [BROTLI_PARAM_QUALITY]: BROTLI_MAX_QUALITY,
        [BROTLI_PARAM_MODE]: mode == 'text' ?
          BROTLI_MODE_TEXT : (
            mode === 'font' ?
              BROTLI_MODE_FONT :
              /* istanbul ignore next */
              BROTLI_MODE_GENERIC
          )
      }),
      createWriteStream(dest),
      err => {
        /* istanbul ignore next */
        if (err) rej(err);
        else res(dest);
      }
    );
  });
})
Example #2
Source File: headers.js    From ucompress with ISC License 6 votes vote down vote up
getLastModified = source => (
  wrap.get(source) ||
  wrap.set(source, new Promise((res, rej) => {
    stat(source, (err, stats) => {
      /* istanbul ignore next */
      if (err) rej(err);
      else res(new Date(stats.mtimeMs).toUTCString());
    });
  }))
)
Example #3
Source File: index.js    From ucompress with ISC License 6 votes vote down vote up
crawl = (source, options) => new Promise((res, rej) => {
  stat(source, (err, stat) => {
    /* istanbul ignore if */
    if (err)
      rej(err);
    else {
      if (stat.isFile())
        copy(source, source, options).then(res, rej);
      /* istanbul ignore else */
      else if (stat.isDirectory())
        readdir(source, (err, files) => {
          /* istanbul ignore if */
          if (err)
            rej(err);
          else
            Promise.all(files
              .filter(file => !/^[._]/.test(file))
              .map(file => crawl(join(source, file), options))
            ).then(res, rej);
        });
    }
  });
})
Example #4
Source File: index.js    From watchlist with MIT License 5 votes vote down vote up
toStats = promisify(stat)