lib/diff.js
function diffFile(existing, proposed, options) {
  let { ensureContents, exists, readChunk } = utils;
  let opts = options || {};

  let contentsA = existing.contents;
  let contentsB = proposed.contents;

  if (!contentsA && exists(existing)) {
    contentsA = readChunk(existing.path, 0, 4 + 4096);
  }

  if (!contentsB && exists(proposed)) {
    contentsB = readChunk(proposed.path, 0, 4 + 4096);
  }

  if ((contentsA && isBuffer(contentsA)) || (contentsB && isBuffer(contentsB))) {
    return diffBinary(existing, proposed);
  }

  ensureContents(existing);
  ensureContents(proposed);
  if (opts.diffText === true) {
    return diffText(existing.contents.toString(), proposed.contents.toString(), opts);
  }
  return diffChars(existing.contents.toString(), proposed.contents.toString(), opts);
}
function diffFile(existing, proposed, options) {
  let { ensureContents, exists, readChunk } = utils;
  let opts = options || {};

  let contentsA = existing.contents;
  let contentsB = proposed.contents;

  if (!contentsA && exists(existing)) {
    contentsA = readChunk(existing.path, 0, 4 + 4096);
  }

  if (!contentsB && exists(proposed)) {
    contentsB = readChunk(proposed.path, 0, 4 + 4096);
  }

  if ((contentsA && isBuffer(contentsA)) || (contentsB && isBuffer(contentsB))) {
    return diffBinary(existing, proposed);
  }

  ensureContents(existing);
  ensureContents(proposed);
  if (opts.diffText === true) {
    return diffText(existing.contents.toString(), proposed.contents.toString(), opts);
  }
  return diffChars(existing.contents.toString(), proposed.contents.toString(), opts);
}
function diffFile ( existing , proposed , options ) { let { ensureContents , exists , readChunk } = utils ; let opts = options || { } ; let contentsA = existing . contents ; let contentsB = proposed . contents ; if ( ! contentsA && exists ( existing ) ) { contentsA = readChunk ( existing . path , 0 , 4 + 4096 ) ; } if ( ! contentsB && exists ( proposed ) ) { contentsB = readChunk ( proposed . path , 0 , 4 + 4096 ) ; } if ( ( contentsA && isBuffer ( contentsA ) ) || ( contentsB && isBuffer ( contentsB ) ) ) { return diffBinary ( existing , proposed ) ; } ensureContents ( existing ) ; ensureContents ( proposed ) ; if ( opts . diffText === true ) { return diffText ( existing . contents . toString ( ) , proposed . contents . toString ( ) , opts ) ; } return diffChars ( existing . contents . toString ( ) , proposed . contents . toString ( ) , opts ) ; }
Returns a formatted diff for binary or text files
Returns a formatted diff for binary or text files