How to use the istextorbinary.isText 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 adamfowleruk / mljs / apps / mljsadmin-workplace / util / mljsadmin.js View on Github external
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;
              }
github codesandbox / codesandbox-importers / packages / import-utils / src / is-text.ts View on Github external
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
      );
    });
  });
github sparkartgroup / gulp-markdown-to-json / lib / plugin.js View on Github external
return new Promise((resolve, reject) => {
    isTextOrBinary.isText(Path.basename(file.path), file.contents, (err, isText) => {
      if (err) return reject(err);
      if (isText) file.isText = true;
      resolve(file);
    });
  });
}
github Nexusoft / NexusInterface / app / nxs_modules / api / modules.js View on Github external
function normalizeFile(path) {
  const stream = fs.createReadStream(path);
  if (isText(path, stream)) {
    const normalizeNewline = streamNormalizeEol('\n');
    return stream.pipe(normalizeNewline);
  } else {
    return stream;
  }
}
github lazd / gulp-replace / index.js View on Github external
result = result.join('');
            }
            else {
              result = chunks.join(replacement);
            }

            file.contents = new Buffer(result);
          }
          return callback(null, file);
        }

        callback(null, file);
      }

      if (options && options.skipBinary) {
        istextorbinary.isText(file.path, file.contents, function(err, result) {
          if (err) {
            return callback(err, file);
          }

          if (!result) {
            callback(null, file);
          } else {
            doReplace();
          }
        });

        return;
      }

      doReplace();
    }
github Nexusoft / NexusInterface / src / shared / lib / modules / repo.js View on Github external
function normalizeFile(path) {
  const stream = fs.createReadStream(path);
  if (isText(path, stream)) {
    const normalizeNewline = normalizeEol('\n');
    return stream.pipe(normalizeNewline);
  } else {
    return stream;
  }
}

istextorbinary

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

Artistic-2.0
Latest version published 4 months ago

Package Health Score

77 / 100
Full package analysis