How to use the isbinaryfile.sync 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 ember-cli / ember-cli / lib / models / file-info.js View on Github external
let promptOptions = {
      type: 'expand',
      name: 'answer',
      default: false,
      message: `${chalk.red('Overwrite')} ${path}?`,
      choices: [
        { key: 'y', name: 'Yes, overwrite', value: 'overwrite' },
        { key: 'n', name: 'No, skip', value: 'skip' },
      ],
    };

    let outputPathIsFile = false;
    try { outputPathIsFile = fs.statSync(this.outputPath).isFile(); } catch (err) { /* ignore */ }

    let canDiff = (
      !isBinaryFile(this.inputPath) && (
        !outputPathIsFile ||
        !isBinaryFile(this.outputPath)
      )
    );

    if (canDiff) {
      promptOptions.choices.push({ key: 'd', name: 'Diff', value: 'diff' });

      if (canEdit()) {
        promptOptions.choices.push({ key: 'e', name: 'Edit', value: 'edit' });
      }
    }

    return this.ui.prompt(promptOptions)
      .then(response => response.answer);
  }
github FormidableLabs / publish-diff / lib / diff.js View on Github external
var isBinary = function (buffer) {
  return (
    // First, check magic numbers to see if we are a possible text file.
    //
    // _Note_: While a `sync`-named method, there's no actual sync I/O when
    // size parameter is provided.
    isBinaryFile.sync(buffer, buffer.length) ||

    // Then check if we have known non-text file types.
    !!fileType(buffer)
  );
};
github todogroup / repolinter / lib / file_system.js View on Github external
isBinaryFile (relativeFile) {
    const file = path.resolve(this.targetDir, relativeFile)
    try {
      return isBinaryFile.sync(file)
    } catch (e) {
      // File doesn't exist or is a directory, so it isn't a binary file
      if (e.message.includes('ENOENT')) {
        return false
      }
      throw e
    }
  }
github KuangPF / vue-cli-analysis / packages / @vue / cli / lib / GeneratorAPI.js View on Github external
function renderFile (name, data, ejsOptions) {
  if (isBinary.sync(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 eserozvataf / sey / src / old / utils / fsManager.js View on Github external
static readFile(pathstr) {
        if (isBinaryFile.sync(pathstr)) {
            return fs.readFileSync(pathstr);
        }

        return fs.readFileSync(pathstr, 'utf8');
    }
github miusuncle / HiveOpenerForVSCode / src / opener.ts View on Github external
export function openFile(target: string) {
    if (isBinaryFile.sync(target)) {
        if (platform.win) {
            childProcess.exec(`explorer "${target}"`);
        }

        if (platform.mac) {
            childProcess.exec(`open "${target}"`);
        }

    } else {
        vscode.workspace.openTextDocument(target).then(doc => {
            const activeEditor = vscode.window.activeTextEditor;
            const column = activeEditor && activeEditor.viewColumn || 1;
            vscode.window.showTextDocument(doc, column);
        });
    }
}
github KuangPF / vue-cli-analysis / packages / @vue / cli / lib / invoke.js View on Github external
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] = isBinary.sync(name)
      ? fs.readFileSync(name)
      : fs.readFileSync(name, 'utf-8')
  }
  return normalizeFilePaths(res)
}
github fabiospampinato / template / dist / middlewares / schema.js View on Github external
_.forOwn(files, function (file, filepath) {
                        if (utils_1.default.template.isFileSkipped(filepath, filter))
                            return;
                        var contents = file.contents;
                        if (isBinary.sync(contents, contents.length))
                            return;
                        var fileSchema = utils_1.default.handlebars.getSchema(contents.toString());
                        _.extend(filesVariables, fileSchema);
                    });
                    return [4 /*yield*/, utils_1.default.loadJSON(path.join(config_1.default.directory, config_1.default.templateConfigName))];
github fabiospampinato / template / src / middlewares / render.ts View on Github external
async function render ( files, metalsmith, next ) {

  const metadata = metalsmith.metadata (),
        render = pify ( consolidate.handlebars.render ),
        paths = Object.keys ( files );

  for ( let path of paths ) {

    const {contents} = files[path];

    if ( isBinary.sync ( contents, contents.length ) ) continue;
    if ( Utils.template.isFileSkipped ( path, metadata.schema.filter ) ) continue;

    const template = contents.toString (),
          rendered = await render ( template, metadata.renderVariables );

    files[path].contents = new Buffer ( rendered );

  }

  next ();

}
github carrot / sprout / lib / helpers.js View on Github external
export function isBinaryFile (src) {
  return isBinary.sync(src)
}

isbinaryfile

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

MIT
Latest version published 3 months ago

Package Health Score

85 / 100
Full package analysis