How to use is-binary-path - 3 common examples

To help you get started, we’ve selected a few is-binary-path 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 saojs / kopy / src / template.js View on Github external
if (typeof condition === 'function') {
            return condition(filepath, ctx)
          }
          return false
        })
    }

    for (const filepath of ctx.fileList) {
      const content = ctx.fileContents(filepath)

      if (shouldSkip && shouldSkip(filepath, content)) {
        continue
      }

      // Skip binary files
      if (isBinaryPath(filepath)) {
        continue
      }

      const absolutePath = ctx.files[filepath].path
      ctx.writeContents(
        filepath,
        render(absolutePath, content, ctx.meta.merged)
      )
    }
  }
}
github nusmodifications / nusmods / api / gulp-tasks / utils / gotCached.js View on Github external
function returnCached() {
    log.info(`returning cached file for ${urlStr}`);
    return fs.readFile(cachedPath);
  }

  const modifiedTime = await getFileModifiedTime(cachedPath, urlStr);
  const maxCacheAge = config.maxCacheAge;
  const isCachedFileValid = modifiedTime && (modifiedTime > Date.now() - (maxCacheAge * 1000));
  if (maxCacheAge === -1 || isCachedFileValid) {
    return returnCached();
  }

  const options = {
    url: urlStr,
    // returns body as a buffer instead of string if its a binary file
    encoding: isBinaryPath(urlStr) ? null : 'utf-8',
    retries(retry) {
      if (retry >= RETRIES) return 0; // Cancels retry
      return 1000 * (retry ** 2);
    },
  };
  if (modifiedTime) {
    options.headers = config.headers || {};
    const modifedTimeString = (new Date(modifiedTime)).toUTCString();
    options.headers['if-modified-since'] = modifedTimeString;
  }

  try {
    const response = await got(urlStr, options);
    let body = response.body;
    if (response.headers['content-type'] === 'text/html') {
      // Serializes the parsed document
github egoist / vue-compile / src / index.ts View on Github external
async normalizeFile(input: string, outFile: string): Promise {
    if (isBinaryPath(input)) {
      const buffer = await fs.readFile(input)
      return this.writeBinary(buffer, {
        filename: input,
        outFile
      })
    }

    let source = await fs.readFile(input, 'utf8')
    source = replaceContants(source, this.options.constants)

    const ctx = {
      filename: input,
      outFile,
      modern: this.options.modern,
      babelrc: this.options.babelrc
    }

is-binary-path

Check if a file path is a binary file

MIT
Latest version published 7 months ago

Package Health Score

76 / 100
Full package analysis

Popular is-binary-path functions