Removes the UTF-8 byte order mark, if any, from a {@link Buffer}.

@param {File} file
@returns {Buffer}
555279
function stripBOM (file) {
  var buffer = file.data;

  if (file.encoding === 'utf8' || file.encoding === 'utf-8') {
    // Check for the UTF-8 byte order mark (0xEFBBBF)
    if (buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
      return buffer.slice(3);
    }
  }

  return buffer;
}
586907
def _remove_accents_(filename):
    
    if isinstance(filename, type(six.u(''))):
        unicode_filename = filename
    else:
        unicode_filename = six.u(filename)
    valid_characters = bytes(b'-_.() 1234567890abcdefghijklmnopqrstuvwxyz')
    cleaned_filename = unicodedata.normalize('NFKD', unicode_filename).encode('ASCII', 'ignore')

    new_filename = six.u('')

    for char_int in bytes(cleaned_filename):
        char_byte = bytes([char_int])
        if char_byte in valid_characters:
            new_filename += char_byte.decode()

    return new_filename
974166
function parseMatter(file, options) {
  const opts = defaults(options);
  const open = opts.delimiters[0];
  const close = '\n' + opts.delimiters[1];
  let str = file.content;

  if (opts.language) {
    file.language = opts.language;
  }

  // get the length of the opening delimiter
  const openLen = open.length;
  if (!utils.startsWith(str, open, openLen)) {
    excerpt(file, opts);
    return file;
  }

  // if the next character after the opening delimiter is
  // a character from the delimiter, then it's not a front-
  // matter delimiter
  if (str.charAt(openLen) === open.slice(-1)) {
    return file;
  }

  // strip the opening delimiter
  str = str.slice(openLen);
  const len = str.length;

  // use the language defined after first delimiter, if it exists
  const language = matter.language(str, opts);
  if (language.name) {
    file.language = language.name;
    str = str.slice(language.raw.length);
  }

  // get the index of the closing delimiter
  let closeIndex = str.indexOf(close);
  if (closeIndex === -1) {
    closeIndex = len;
  }

  // get the raw front-matter block
  file.matter = str.slice(0, closeIndex);

  const block = file.matter.replace(/^\s*#[^\n]+/gm, '').trim();
  if (block === '') {
    file.isEmpty = true;
    file.empty = file.content;
    file.data = {};
  } else {

    // create file.data by parsing the raw file.matter block
    file.data = parse(file.language, file.matter, opts);
  }

  // update file.content
  if (closeIndex === len) {
    file.content = '';
  } else {
    file.content = str.slice(closeIndex + close.length);
    if (file.content[0] === '\r') {
      file.content = file.content.slice(1);
    }
    if (file.content[0] === '\n') {
      file.content = file.content.slice(1);
    }
  }

  excerpt(file, opts);

  if (opts.sections === true || typeof opts.section === 'function') {
    sections(file, opts.section);
  }
  return file;
}
209185
function(file){
        file = file.split(os.EOL);
        file = this._formatFileArray(file);
        file = this._groupFormatData(file);
        this._dataCache = file;
        return this;
    }
430603
function read(file) {
    var data = fs.readFileSync(file, 'ascii');
    // Strip comments
    data = data.replace(/#.*/g, '');
    var lines = data.split('\n');
    for (var i = 0, len = lines.length; i < len; i++) {
        var line = lines[i].trim();
        if (!line) {
            continue;
        }

        var words = line.split(/\s/),
            type = words.shift(),
            suffixes = words;

        for (var j = 0, jen = suffixes.length; j < jen; j++) {
            var suff = suffixes[j].trim();
            if (!suff) {
                continue;
            }

            addType(type, '.' + suff);
        }
    }
}
914971
function utf16End(buf) {
  var r = buf && buf.length ? this.write(buf) : '';
  if (this.lastNeed) {
    var end = this.lastTotal - this.lastNeed;
    return r + this.lastChar.toString('utf16le', 0, end);
  }
  return r;
}
47152
function utf8Text(buf, i) {
  var total = utf8CheckIncomplete(this, buf, i);
  if (!this.lastNeed) return buf.toString('utf8', i);
  this.lastTotal = total;
  var end = buf.length - (total - this.lastNeed);
  buf.copy(this.lastChar, 0, end);
  return buf.toString('utf8', i, end);
}
1001372
function read(file){
	var fd = fs.readFileSync(file);

	if(isUtf8(fd)){
		var bf = fs.readFileSync(file);
	} else {
		var bf = iconv.encode(iconv.decode(fd, 'gbk'),'utf8');
	}
	return bf;
}
936633
function(str) {

    var _str = str;
    var _pos = 0;
    var _buffer = 0;
    var _buflen = 0;

    var _this = {};

    _this.read = function() {

	while (_buflen < 8) {

	    if (_pos >= _str.length) {
		if (_buflen == 0) {
		    return -1;
		}
		throw new Error('unexpected end of file./' + _buflen);
	    }

	    var c = _str.charAt(_pos);
	    _pos += 1;

	    if (c == '=') {
		_buflen = 0;
		return -1;
	    } else if (c.match(/^\s$/) ) {
		// ignore if whitespace.
		continue;
	    }

	    _buffer = (_buffer << 6) | decode(c.charCodeAt(0) );
	    _buflen += 6;
	}

	var n = (_buffer >>> (_buflen - 8) ) & 0xff;
	_buflen -= 8;
	return n;
    };

    var decode = function(c) {
	if (0x41 <= c && c <= 0x5a) {
	    return c - 0x41;
	} else if (0x61 <= c && c <= 0x7a) {
	    return c - 0x61 + 26;
	} else if (0x30 <= c && c <= 0x39) {
	    return c - 0x30 + 52;
	} else if (c == 0x2b) {
	    return 62;
	} else if (c == 0x2f) {
	    return 63;
	} else {
	    throw new Error('c:' + c);
	}
    };

    return _this;
}
179535
function getFileExtension(file) {
    return file.name.substring(file.name.lastIndexOf('.')+1, file.name.length).toLowerCase()
}
1037411
function decodeFile (args) {
    var file = args.file;
    var next = args.next;

    if (file.encoding && (isTypedArray(file.data) || Array.isArray(file.data))) {
      try {
        // Normalize the data to 2-byte characters
        var characterArray = new Uint16Array(file.data);

        // Convert the characters to a string
        var string = String.fromCharCode.apply(null, characterArray);

        // Remove the byte order mark, if any
        return stripBOM(string);
      }
      catch (err) {
        // Unknown encoding, so just call the next decoder plugin
        next();
      }
    }
    else {
      // The file data is not a supported data type, so call the next decoder plugin
      next();
    }
  }
485912
function isJsFile(file) {
    "use strict";
    var ext = fileExt(file);
    var valid = Object.keys(require.extensions).map(function(val) {
        return val.replace(/^\./, '');
    }).filter(function(ext) {
        return ext === 'js' || ext === 'coffee';
    });
    return isString(ext, "string") && valid.indexOf(ext) !== -1;
}
1339196
public static String normalizeDriveLetter(String file) {
        if (file.length() > 2 && file.charAt(1) == ':') {
            return Character.toUpperCase(file.charAt(0)) + file.substring(1);
        } else if (file.length() > 3 && file.charAt(0) == '*'
                   && file.charAt(2) == ':') {
            // Handle a wildcard * at the beginning of the string.
            return file.substring(0, 1) + Character.toUpperCase(file.charAt(1))
                   + file.substring(2);
        }
        return file;
    }
1019482
function cssToJsFn(filePath, file) {
    var STYLE_HEADER = 'css = \'',
        STYLE_FOOTER = '\';';

    var css = new CleanCss({})
        .minify(file.contents.toString())
        .styles;

    file.contents = new Buffer(STYLE_HEADER + escapeStr(css) + STYLE_FOOTER);

    return file.contents.toString('utf8');
}
422625
def _detect_buffer_encoding(self, f):
        """"""

        encoding = None
        with contextlib.closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)) as m:
            encoding = self._analyze_file(m)
        return encoding
215010
public String canonizeString(String file) {
        int i = 0;
        int lim = file.length();

        // Remove embedded /../
        while ((i = file.indexOf("/../")) >= 0) {
            if ((lim = file.lastIndexOf('/', i - 1)) >= 0) {
                file = file.substring(0, lim) + file.substring(i + 3);
            } else {
                file = file.substring(i + 3);
            }
        }
        // Remove embedded /./
        while ((i = file.indexOf("/./")) >= 0) {
            file = file.substring(0, i) + file.substring(i + 2);
        }
        // Remove trailing ..
        while (file.endsWith("/..")) {
            i = file.indexOf("/..");
            if ((lim = file.lastIndexOf('/', i - 1)) >= 0) {
                file = file.substring(0, lim+1);
            } else {
                file = file.substring(0, i);
            }
        }
        // Remove trailing .
        if (file.endsWith("/."))
            file = file.substring(0, file.length() -1);

        return file;
    }
1032590
private static String decompress(File file) throws IOException {
        if (file == null || !file.exists()) {
            return Constants.EMPTY_STRING;
        }

        byte[] bytes = Base64.getDecoder().decode(IOUtils.toByteArray(new FileInputStream(file)));
        GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
        BufferedReader bf = new BufferedReader(new InputStreamReader(gzipInputStream, UTF_8));
        StringBuilder outStr = new StringBuilder(Constants.EMPTY_STRING);
        String line;
        while ((line = bf.readLine()) != null) {
            outStr.append(line);
        }
        return outStr.toString();
    }