Helper function that detects whether a buffer is binary or utf8.
@param {Buffer} buffer
@returns {boolean}
500123
function isBinary(buffer) {
  var chunk = buffer.toString('utf8', 0, Math.min(buffer.length, 24));
  for (var i in chunk) {
    var charCode = chunk.charCodeAt(i);
    if (charCode == 65533 || charCode <= 8) {
      return true;
    }
  }
  return false;
}
708511
function (buffer, start, length) {
  /*jshint bitwise:false*/

  var isNested = buffer instanceof ByteBuffer;

  this.buffer = isNested ? buffer.buffer : buffer;
  this.start = (start || 0) + (isNested ? buffer.start : 0);
  this.length = length || (this.buffer.length - this.start);
  this.offset = 0;

}
1053937
function(data) {

    var _mode = QRMode.MODE_8BIT_BYTE;
    var _data = data;
    var _parsedData = [];

    var _this = {};


    // Added to support UTF-8 Characters
    for (var i = 0, l = _data.length; i < l; i++) {
	var byteArray = [];
	var code = _data.charCodeAt(i);

	if (code > 0x10000) {
	    byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
	    byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
	    byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
	    byteArray[3] = 0x80 | (code & 0x3F);
	} else if (code > 0x800) {
	    byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
	    byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
	    byteArray[2] = 0x80 | (code & 0x3F);
	} else if (code > 0x80) {
	    byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
	    byteArray[1] = 0x80 | (code & 0x3F);
	} else {
	    byteArray[0] = code;
	}

        // Fix Unicode corruption bug
        _parsedData.push(byteArray);
    }

    _parsedData = Array.prototype.concat.apply([], _parsedData);

    if (_parsedData.length != _data.length) {
	_parsedData.unshift(191);
	_parsedData.unshift(187);
	_parsedData.unshift(239);
    }

    var _bytes = _parsedData;

    _this.getMode = function() {
	return _mode;
    };

    _this.getLength = function(buffer) {
	return _bytes.length;
    };

    _this.write = function(buffer) {
	for (var i = 0; i < _bytes.length; i += 1) {
	    buffer.put(_bytes[i], 8);
	}
    };

    return _this;
}
1020231
function(data, encoding) {
      if (encoding == null) {
        encoding = 'hex';
      }
      if (Array.isArray(data)) {
        return data;
      }
      switch (encoding) {
        case 'base64':
          return Gibberish.base64.decode(data);
        case 'hex':
          return Gibberish.h2a(data);
        case 'utf8':
          return Gibberish.s2a(data);
        default:
          throw new Error("Encoding not supported");
      }
    }
978616
function(b) {
  var b2 = b.getByte();
  if(b2 === 0x80) {
    return undefined;
  }

  // see if the length is "short form" or "long form" (bit 8 set)
  var length;
  var longForm = b2 & 0x80;
  if(!longForm) {
    // length is just the first byte
    length = b2;
  } else {
    // the number of bytes the length is specified in bits 7 through 1
    // and each length byte is in big-endian base-256
    length = b.getInt((b2 & 0x7F) << 3);
  }
  return length;
}
963356
function isPctEncoded (chr) {
        if (!isPercentDigitDigit(chr, 0)) {
            return false;
        }
        var firstCharCode = parseHex2(chr, 1);
        var numBytes = utf8.numBytes(firstCharCode);
        if (numBytes === 0) {
            return false;
        }
        for (var byteNumber = 1; byteNumber < numBytes; byteNumber += 1) {
            if (!isPercentDigitDigit(chr, 3*byteNumber) || !utf8.isValidFollowingCharCode(parseHex2(chr, 3*byteNumber + 1))) {
                return false;
            }
        }
        return true;
    }
283634
function (file) {
      var result = getRawData(file), type = JSZip.utils.getTypeOf(result);
      if (type === "string") {
         if (!file.options.binary) {
            // unicode text !
            // unicode string => binary string is a painful process, check if we can avoid it.
            if (JSZip.support.uint8array && typeof TextEncoder === "function") {
               return TextEncoder("utf-8").encode(result);
            }
            if (JSZip.support.nodebuffer) {
               return new Buffer(result, "utf-8");
            }
         }
         return file.asBinary();
      }
      return result;
   }
1236264
function(other) {

    // If sign bits differ ...
    if ((this.buffer[this.offset] & 0x80) != (other.buffer[other.offset] & 0x80)) {
      return other.buffer[other.offset] - this.buffer[this.offset];
    }

    // otherwise, compare bytes lexicographically
    for (var i = 0; i < 8; i++) {
      if (this.buffer[this.offset+i] !== other.buffer[other.offset+i]) {
        return this.buffer[this.offset+i] - other.buffer[other.offset+i];
      }
    }
    return 0;
  }
1183414
function __encode_utf8(text) {

        // Fill buffer with UTF-8
        for (var i=0; i<text.length; i++) {
            var codepoint = text.charCodeAt(i);
            __append_utf8(codepoint);
        }

        // Flush buffer
        if (length > 0) {
            var out_buffer = buffer.subarray(0, length);
            length = 0;
            return out_buffer;
        }

    }
809811
function bnToBuffer( bn ) {
  var hex = bn.toString( 16 )
  hex = hex.length % 2 === 1 ? '0' + hex : hex
  return Buffer.from( hex, 'hex' )
}
512391
function UTF8Length(input) {
		var output = 0;
		for (var i = 0; i<input.length; i++) 
		{
			var charCode = input.charCodeAt(i);
				if (charCode > 0x7FF)
				   {
					  // Surrogate pair means its a 4 byte character
					  if (0xD800 <= charCode && charCode <= 0xDBFF)
						{
						  i++;
						  output++;
						}
				   output +=3;
				   }
			else if (charCode > 0x7F)
				output +=2;
			else
				output++;
		} 
		return output;
	}
759248
function(bytes) {
  var result = "";
  var i = 0;
  var wc;
  var c;

  while (i < bytes.length) {
    /* parse as UTF-8 lead byte */
    wc = bytes[i++];
    if (wc < 0x80) {
      count = 0;
    } else if (wc < 0xC2 || wc >= 0xF8) {
      throw new Error("input is not a valid UTF-8 lead octet");
    } else if (wc < 0xE0) {
      count = 1;
      wc = (wc & 0x1F) << 6;
    } else if (wc < 0xF0) {
      count = 2;
      wc = (wc & 0x0F) << 12;
    } else /* wc < 0xF8 */ {
      count = 3;
      wc = (wc & 0x07) << 18;
    }

    /* parse trail bytes, if any */
    while (count) {
      if (!(i < bytes.length)) {
        throw new Error("short read");
      }
      if ((c = bytes[i++] ^ 0x80) > 0x3F) {
        throw new Error("input is not a valid UTF-8 trail octet");
      }
      wc |= c << (6 * --count);
      if (wc < (1 << (5 * count + 6))) {
        throw new Error("invalid non-minimal encoded input");
      }
    }

    /* handle conversion to UTF-16 if needed */
    if (wc > 0xFFFF) {
      wc -= 0x10000;
      result += String.fromCharCode(0xD800 + (wc >> 10));
      wc = 0xDC00 + (wc & 0x3FF);
    }
    result += String.fromCharCode(wc);
  }

  return result;
}
1294214
function is_utf8(&$string)
	{
		if ($string === mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
			return true;
		}

		if ($this->ignore_invalid_utf8) {
			$string = mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32");
			return true;
		}

		return false;
	}
105417
function(size) {
    var match;
    var buffer;
    if (match = size.match(/(\d+)KB/)) {
      buffer = new Buffer(parseInt(match[1]) * 1024);
    } else if (match = size.match(/(\d+)MB/)) {
      buffer = new Buffer(parseInt(match[1]) * 1024 * 1024);
    } else {
      switch (size) {
        case 'empty': buffer = new Buffer(0); break;
        case 'small': buffer = new Buffer(1024 * 1024); break;
        case 'large': buffer = new Buffer(1024 * 1024 * 20); break;
        default: return new Buffer(1024 * 1024);
      }
    }
    buffer.fill('x');
    return buffer;
  }
1335908
def utf8(string):
    
    if isinstance(string, six.text_type):
        return string.encode('utf8')
    elif isinstance(string, six.binary_type):
        return string
    else:
        return six.text_type(string).encode('utf8')
91191
function bufferToScript(buffer, enc) {
    if (buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) { // UTF8 BOM sequence, see http://en.wikipedia.org/wiki/Byte_order_mark
        buffer = buffer.slice(3, buffer.length - 3);
    }

    var script = buffer.toString(enc);

    script = script.replace(/^\s*#!/g, "//$&"); // UNIX-style shebang, see http://en.wikipedia.org/wiki/Shebang_(Unix)
    return script;
}
796656
function _addBigIntegerToBuffer(buffer, val) {
  var hexVal = val.toString(16);
  // ensure 2s complement +ve
  if(hexVal[0] >= '8') {
    hexVal = '00' + hexVal;
  }
  var bytes = forge.util.hexToBytes(hexVal);
  buffer.putInt32(bytes.length);
  buffer.putBytes(bytes);
}