How to use the isbinaryfile.isBinaryFileSync function in isbinaryfile

To help you get started, we’ve selected a few isbinaryfile 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 teambit / bit / src / utils / eol.js View on Github external
function converts(text: string | Buffer, to: string) {
  if (Buffer.isBuffer(text)) {
    if (isBinaryFileSync(text)) return text; // don't touch binary files
    newLines.forEach((newLine) => {
      // $FlowFixMe text is Buffer here
      if (newLine !== to) text = replaceBuffer(text, newLine, to);
    });
    return text;
  }
  return text.toString().replace(newline, to);
}
github luoxue-victor / webpack-box / packages / cli / lib / GeneratorAPI.js View on Github external
function renderFile (name, data, ejsOptions) {
  if (isBinaryFileSync(name)) {
    return fs.readFileSync(name) // return buffer
  }
  const template = fs.readFileSync(name, 'utf-8')

  // custom template inheritance via yaml front matter.
  // ---
  // extend: 'source-file'
  // replace: !!js/regexp /some-regex/
  // OR
  // replace:
  //   - !!js/regexp /foo/
  //   - !!js/regexp /bar/
  // ---
  const yaml = require('yaml-front-matter')
  const parsed = yaml.loadFront(template)
  const content = parsed.__content
github SBoudrias / mem-fs-editor / lib / actions / copy-tpl.js View on Github external
function render(contents, filename, context, tplSettings) {
  let result;

  const contentsBuffer = Buffer.from(contents, 'binary');
  if (isBinaryFileSync(contentsBuffer, contentsBuffer.length)) {
    result = contentsBuffer;
  } else {
    result = ejs.render(
      contents.toString(),
      context,
      // Setting filename by default allow including partials.
      extend({filename: filename}, tplSettings)
    );
  }

  return result;
}
github salesforce / sfdx-lwc-jest / scripts / checkLicenseHeaders.js View on Github external
file =>
      INCLUDED_PATTERNS.some(pattern => pattern.test(file)) &&
      !IGNORED_PATTERNS.some(pattern => pattern.test(file)) &&
      !isDirectory(file) &&
      !isBinaryFileSync(file) &&
      needsCopyrightHeader(file)
  );
github silverwind / droppy / server / utils.js View on Github external
utils.contentType = function(p) {
  const type = mimeTypes.lookup(p);
  if (overrideMimeTypes[type]) return overrideMimeTypes[type];

  if (type) {
    const charset = mimeTypes.charsets.lookup(type);
    return type + (charset ? "; charset=" + charset : "");
  } else {
    try {
      return isbinaryfile.isBinaryFileSync(p) ? "application/octet-stream" : "text/plain";
    } catch (err) {
      return "application/octet-stream";
    }
  }
};
github bazelbuild / rules_nodejs / internal / pkg_npm / packager.js View on Github external
function copyWithReplace(src, dest, substitutions) {
  mkdirp(path.dirname(dest));
  if (fs.lstatSync(src).isDirectory()) {
    const files = fs.readdirSync(src)
    files.forEach((relativeChildSrc) => {
      const childSrc = path.join(src, relativeChildSrc);
      const childDest = path.join(dest, path.basename(childSrc));
      copyWithReplace(childSrc, childDest, substitutions);
    });
  } else if (!isBinary(src)) {
    let content = fs.readFileSync(src, {encoding: 'utf-8'});
    substitutions.forEach(r => {
      const [regexp, newvalue] = r;
      content = content.replace(regexp, newvalue);
    });
    fs.writeFileSync(dest, content);
  } else {
    fs.copyFileSync(src, dest);
  }
}
github vuejs / vue-cli / packages / @vue / cli / lib / util / readFiles.js View on Github external
module.exports = async function readFiles (context) {
  const files = await globby(['**'], {
    cwd: context,
    onlyFiles: true,
    gitignore: true,
    ignore: ['**/node_modules/**', '**/.git/**'],
    dot: true
  })
  const res = {}
  for (const file of files) {
    const name = path.resolve(context, file)
    res[file] = isBinaryFileSync(name)
      ? fs.readFileSync(name)
      : fs.readFileSync(name, 'utf-8')
  }
  return normalizeFilePaths(res)
}
github alibaba / ice / tools / iceworks / renderer / src / pages / Home / ProjectDashboard / Todo.jsx View on Github external
files.forEach((file) => {
    if (ignoreFiles.includes(file)) {
      return;
    }
    const fullPath = path.join(dirPath, file);
    stats = fs.lstatSync(fullPath);
    if (stats.isDirectory()) {
      list = list.concat(recursiveReaddirSync(fullPath, rootDir));
    } else if (!isBinaryFileSync(fullPath)) {
      list.push([path.relative(rootDir, fullPath), fullPath]);
    }
  });
github quasarframework / quasar / app / lib / app-extension / Extension.js View on Github external
if (answer.action === 'overwriteAll') {
          overwrite = 'overwriteAll'
        }
        else if (answer.action === 'skipAll') {
          overwrite = 'skipAll'
          continue
        }
        else if (answer.action === 'skip') {
          continue
        }
      }
    }

    fs.ensureFileSync(targetPath)

    if (rawCopy || isBinary(sourcePath)) {
      fs.copyFileSync(sourcePath, targetPath)
    }
    else {
      const rawContent = fs.readFileSync(sourcePath, 'utf-8')
      const template = compileTemplate(rawContent, { 'interpolate': /<%=([\s\S]+?)%>/g })
      fs.writeFileSync(targetPath, template(scope), 'utf-8')
    }
  }
}

isbinaryfile

Detects if a file is binary in Node.js. Similar to Perl's -B.

MIT
Latest version published 5 months ago

Package Health Score

81 / 100
Full package analysis