pax_global_header00006660000000000000000000000064126351535260014522gustar00rootroot0000000000000052 comment=cc4c44ce979a7c0ca0a6308f64b017baba3616ed is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/000077500000000000000000000000001263515352600202225ustar00rootroot00000000000000is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/LICENSE000066400000000000000000000020731263515352600212310ustar00rootroot00000000000000The MIT License (MIT) Copyright (C) 2014 Wei Fanzhe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 銆銆 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/README.md000066400000000000000000000006151263515352600215030ustar00rootroot00000000000000#utf8 detector Detect if a Buffer is utf8 encoded. It need The minimum amount of bytes is 4. ```javascript var fs = require('fs'); var isUtf8 = require('is-utf8'); var ansi = fs.readFileSync('ansi.txt'); var utf8 = fs.readFileSync('utf8.txt'); console.log('ansi.txt is utf8: '+isUtf8(ansi)); //false console.log('utf8.txt is utf8: '+isUtf8(utf8)); //true ``` is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/ansi.txt000077500000000000000000000004721263515352600217230ustar00rootroot00000000000000zheasdf 传李晨张馨予因压力大分手 侯佩岑晒夫妻出游照(图集) 图集:刘亦菲与干爹陈金飞私照 佟丽娅为金鹰节假唱致歉 章子怡默认与撒贝宁恋情:心里有数就行 刘恺威谈婚期态度反复 图集:日本巨乳童颜女星泳装写真 隋唐裹床单压轴走秀 图集:Hold住姐翘二郎腿 蔡琴默认与富商男友分手 图集:港三级片首映女星低胸亮相 李嘉欣自曝无意再造人 is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/is-utf8.js000066400000000000000000000047141263515352600220650ustar00rootroot00000000000000 exports = module.exports = function(bytes) { var i = 0; while(i < bytes.length) { if( (// ASCII bytes[i] == 0x09 || bytes[i] == 0x0A || bytes[i] == 0x0D || (0x20 <= bytes[i] && bytes[i] <= 0x7E) ) ) { i += 1; continue; } if( (// non-overlong 2-byte (0xC2 <= bytes[i] && bytes[i] <= 0xDF) && (0x80 <= bytes[i+1] && bytes[i+1] <= 0xBF) ) ) { i += 2; continue; } if( (// excluding overlongs bytes[i] == 0xE0 && (0xA0 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) ) || (// straight 3-byte ((0xE1 <= bytes[i] && bytes[i] <= 0xEC) || bytes[i] == 0xEE || bytes[i] == 0xEF) && (0x80 <= bytes[i + 1] && bytes[i+1] <= 0xBF) && (0x80 <= bytes[i+2] && bytes[i+2] <= 0xBF) ) || (// excluding surrogates bytes[i] == 0xED && (0x80 <= bytes[i+1] && bytes[i+1] <= 0x9F) && (0x80 <= bytes[i+2] && bytes[i+2] <= 0xBF) ) ) { i += 3; continue; } if( (// planes 1-3 bytes[i] == 0xF0 && (0x90 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) ) || (// planes 4-15 (0xF1 <= bytes[i] && bytes[i] <= 0xF3) && (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) ) || (// plane 16 bytes[i] == 0xF4 && (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x8F) && (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) ) ) { i += 4; continue; } return false; } return true; } is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/package.json000066400000000000000000000005441263515352600225130ustar00rootroot00000000000000{ "name": "is-utf8", "version": "0.2.1", "description": "Detect if a buffer is utf8 encoded.", "main": "is-utf8.js", "scripts": { "test": "node test.js" }, "repository": "https://github.com/wayfind/is-utf8.git", "keywords": [ "utf8", "charset" ], "files": [ "is-utf8.js" ], "author": "wayfind", "license": "MIT" } is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/test.js000066400000000000000000000003571263515352600215440ustar00rootroot00000000000000var fs = require('fs'); var isUtf8 = require('./is-utf8.js'); var ansi = fs.readFileSync('ansi.txt'); var utf8 = fs.readFileSync('utf8.txt'); console.log('ansi.txt is utf8: '+isUtf8(ansi)); console.log('utf8.txt is utf8: '+isUtf8(utf8)); is-utf8-cc4c44ce979a7c0ca0a6308f64b017baba3616ed/utf8.txt000077500000000000000000000007231263515352600216560ustar00rootroot00000000000000asdfasdaaf 浼犳潕鏅ㄥ紶棣ㄤ簣鍥犲帇鍔涘ぇ鍒嗘墜 渚僵宀戞檼澶鍑烘父鐓(鍥鹃泦) 鍥鹃泦:鍒樹害鑿蹭笌骞茬埞闄堥噾椋炵鐓 浣熶附濞呬负閲戦拱鑺傚亣鍞辫嚧姝 绔犲瓙鎬¢粯璁や笌鎾掕礉瀹佹亱鎯:蹇冮噷鏈夋暟灏辫 鍒樻伜濞佽皥濠氭湡鎬佸害鍙嶅 鍥鹃泦锛氭棩鏈法涔崇棰滃コ鏄熸吵瑁呭啓鐪 闅嬪攼瑁瑰簥鍗曞帇杞磋蛋绉 鍥鹃泦锛欻old浣忓缈樹簩閮庤吙 钄$惔榛樿涓庡瘜鍟嗙敺鍙嬪垎鎵 鍥鹃泦锛氭腐涓夌骇鐗囬鏄犲コ鏄熶綆鑳镐寒鐩 鏉庡槈娆h嚜鏇濇棤鎰忓啀閫犱汉