Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "istextorbinary in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'istextorbinary' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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;
    };
fs.readFile(settings.folder + "/" + file, function(err,data) {


            if (err) {
              //crapout(err);
              console.log("    - ERROR reading file prior to save: " + settings.folder + "/" + file);
              deferred2.resolve(settings.folder + "/" + file);
            } else {
              itob.isText(file,data,function (err,result) {
                if (result) {
                  data = data.toString(); // convert to string if utf8, otherwise leave as binary buffer
                }

              // actually upload the file once working

              var vf = settings.folder;
              if (settings.stripBaseFolder) {
                vf = settings.folder.substring(base.length + 1);
              }
              /*if (0 == vf.indexOf("/")) {
                vf = vf.substring(1);
              }*/
              if (0 != vf.indexOf("/") && vf.length != 0) {
                vf = "/" + vf;
              }
return new Promise((resolve, reject) => {
    _isText(filename, buffer, (err: Error, result: boolean) => {
      if (err) {
        return reject(err);
      }

      // We don't support null bytes in the database with postgres,
      // so we need to mark it as binary if there are null bytes
      const hasNullByte = buffer.toString().includes("\0");

      resolve(
        result &&
          !FILE_LOADER_REGEX.test(filename) &&
          !isTooBig(buffer) &&
          !hasNullByte
      );
    });
  });
'use strict';

const Promise = require('bluebird');
const Path = require('path');
const co = require('co');
const _ = require('lodash');
const fs = Promise.promisifyAll(require('fs'));
const readFile = Promise.promisify(fs.readFile);
const isBinary = Promise.promisify(require('istextorbinary').isBinary);
const utils = require('./utils');
const glob = require('globby');

const notBinary = ['.nunj', '.nunjucks', '.hbs', '.handlebars', '.jsx', '.twig']; // TODO: handle this in a scalable, extendable way

module.exports = {

    describe(dir, relDir, filter) {
        filter = filter || (filePath => !(/(^|\/)\.[^\/\.]/g).test(filePath));

        return dirscribe(dir, {
            filter: filter,
            after: files => _.orderBy(files, ['isDirectory', 'order', 'path'], ['desc', 'asc', 'asc']),
            build: build,
        });
files.forEach(file =>{
      let fileName = path.join(this.output, path.relative(this.path,file));
      const buffer = fs.readFileSync(file);
      let shouldCompile = true;

      if(!isTextOrBinary.isTextSync(fileName, buffer)){//如果测试为binary文件,就不解析content,当然文件名还是得解析的
          logger.log("debug", {message: `文件${fileName}为二进制文件,不解析文件内容,直接复制`});
          shouldCompile = false;
      }
      //解析文件名
      try {
        // 使用strict模式,会提示未定义field错误
        fileName = Handlebars.compile(fileName, {strict: true})(this.data);
      } catch (e) {
        logger.log('error', {message: `生成文件${fileName} 时出现错误: ${e}`});
        fileName = Handlebars.compile(fileName)(this.data); // 非严格模式下重新编译
      }
      let fileContent;
      if(shouldCompile) {
        if (fs.existsSync(fileName) && !this.overwrite) {
          logger.log("debug", {message: `${fileName} 已存在,将保留该文件内容`});
          return;
module.exports.parse = function parseString({ feed, data }, next) {
	// Detect
	const isText = require('istextorbinary').isTextSync(feed.basename, data)
	if (!isText) {
		next()
	} else {
		// Parse
		next(null, data.toString())
	}
}
files.forEach(file => {
      const from = path.join(src, file);
      const to = path.join(targetDir, this.replaceTemplate(this.fileMapping[file] || file, locals));
      const content = fs.readFileSync(from);
      this.log('write to %s', to);

      // check if content is a text file
      const result = isTextOrBinary.isTextSync(from, content)
        ? this.replaceTemplate(content.toString('utf8'), locals)
        : content;

      mkdirp.sync(path.dirname(to));
      fs.writeFileSync(to, result);
    });
    return files;
return async (fileStream) => {
    let value = await decompress(fileStream);

    // is Buffer or string? >:D
    if (!this.supportBuffer || require('istextorbinary').isTextSync(false, value)) {
      debug('convert to string');
      value = value.toString();
    } else {
      debug('keep data as Buffer');
    }

    return new CacheEntry(true, filePath, value);
  };
}
readFileSync: function (absolute) {
    const stat = fs.statSync(absolute)
    if (stat.size > 1000000) {
      console.warn(('[warn] File which exceeds 1MB limited detected: ' + absolute).yellow)
      return ''
    }
    const buffer = fs.readFileSync(absolute)
    if (!istext.isTextSync(absolute, buffer)) {
      console.warn(('[warn] Binary file detected when expected text: ' + absolute).yellow)
      return ''
    }
    const contents = buffer.toString().trim()
    return contents
  },
  readFile: function (absolute, done) {
'use strict';

const Promise   = require('bluebird');
const Path      = require('path');
const co        = require('co');
const _         = require('lodash');
const dirscribe = require('@allmarkedup/dirscribe');
const fs        = require('fs');
const readFile  = Promise.promisify(fs.readFile);
const isBinary  = Promise.promisify(require('istextorbinary').isBinary);
const utils     = require('./utils');
const console       = require('./console');

module.exports = {

    describe(dir, noCache) {

        dir = Path.resolve(dir);

        return dirscribe(dir, {
            filter: filePath => !(/(^|\/)\.[^\/\.]/g).test(filePath),
            after:  files => _.orderBy(files, ['type', 'order', 'path'], ['desc', 'asc', 'asc']),
            build:  build
        });

        function build(filePath, stat) {

Is your System Free of Underlying Vulnerabilities?
Find Out Now