How to use the istextorbinary.isBinarySync function in istextorbinary

To help you get started, we’ve selected a few istextorbinary 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 frctl / fractal / src / filesystem / entity.js View on Github external
this.relativeDir        = relativefileInfo.dir;

        this.pathSegments       = _.compact(this.path.split('/'));
        this.depth              = this.pathSegments.length;

        this.modified           = this.stat.mtime;

        this.order              = nameParts ? parseInt(nameParts[1], 10) : 10000; // Can't use Infinity as it converts to NULL on JSON stringification!
        this.hidden             = !! _.find(this.pathSegments, function(segment){
                                    return segment.charAt(0) === '_';
                                });

        if (this.isFile()) {
            this.raw = this.contents;
            this.lang = this.ext.replace(/^\./,'').toLowerCase();
            this.isBinary = tob.isBinarySync(this.relativePath, this.contents);
        }

        return this;
    };
github strongloop / generator-loopback / lib / actions.js View on Github external
copy(source, dest) {
      dest = dest || source;
      source = this.templatePath(source);
      var headers = readChunk.sync(source, 0, 512);

      if (istextorbinary.isBinarySync(undefined, headers)) {
        this.fs.copy(source, this.destinationPath(dest));
      } else {
        this.template(source, dest);
      }
    }
github yeoman / generator / lib / util / binary-diff.js View on Github external
exports.isBinary = (existingFilePath, newFileContents) => {
  const existingHeader = readChunk.sync(existingFilePath, 0, 512);
  return (
    istextorbinary.isBinarySync(existingFilePath, existingHeader) ||
    (newFileContents && istextorbinary.isBinarySync(existingFilePath, newFileContents))
  );
};
github kdzwinel / betwixt / lib / captured-connection.js View on Github external
function isBinary(contentType, buffer) {
    let type = getResourceType(contentType);

    //TODO Image is not always binary (SVG)
    if (type === 'Image' || type === 'Media' || type === 'Font') {
        return true;
    }

    if (type === 'Other' && isTextOrBinary.isBinarySync(buffer)) {
        return true;
    }

    return false;
}
github kdzwinel / betwixt / src / lib / captured-connection.js View on Github external
function isBinary(contentType, buffer) {
    let type = getResourceType(contentType);

    //TODO Image is not always binary (SVG)
    if (type === 'Image' || type === 'Media' || type === 'Font') {
        return true;
    }

    if (type === 'Other' && isTextOrBinary.isBinarySync(buffer)) {
        return true;
    }

    return false;
}
github NishantSinghChandel / reactjs-component-generator / src / generate.js View on Github external
function run(file, done) {
    if (
      isTextOrBinary.isBinarySync(path.basename(file), files[file].contents)
    ) {
      done();
      return;
    }

    let str = files[file].contents.toString();
    render(str, metadata, function(err, res) {
      if (err) {
        return done(err);
      }
      files[file].contents = new Buffer(res);
      done();
    });
  }
}
github yeoman / generator / lib / actions / actions.js View on Github external
actions.copy = function copy(source, dest) {
  dest = dest || source;
  source = this.templatePath(source);
  var headers = readChunk.sync(source, 0, 512);

  if (istextorbinary.isBinarySync(undefined, headers)) {
    this.fs.copy(source, this.destinationPath(dest));
  } else {
    this.template(source, dest);
  }

  return this;
};

istextorbinary

Determine if a filename and/or buffer is text or binary. Smarter detection than the other solutions.

Artistic-2.0
Latest version published 12 months ago

Package Health Score

79 / 100
Full package analysis