function stringIsText(text) {
    var isText = true;
    var sampleSize = Math.min(100, text.length);
    for (var i = 0; i < sampleSize; i++) {
        var charCode = text.charCodeAt(i);
        if (charCode === 65533 || charCode <= 8) {
            isText = false;
            break;
        }
    }
    return isText;
}
Function to check if the string is text or binary, based on the
answers here:
  http://stackoverflow.com/questions/10225399/check-if-a-file-is-binary-or-ascii-with-node-js