# juniversalchardet **Repository Path**: lovesxinger/juniversalchardet ## Basic Information - **Project Name**: juniversalchardet - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 15 - **Created**: 2022-04-26 - **Last Updated**: 2022-04-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # juniversalchardet ## 简介 >juniversalchardet 是一个字符编码高效识别检测库 ![动画](./动画.gif) ## 下载安装 ``` npm install @ohos/juniversalchardet --save ``` OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony npm包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_npm_usage.md) 。 ## 使用说明 ### 文本编码检测 ``` // 编码检测:输入目标检测文件 UniversalDetector.detectCharset(path); // 向编码检测器提供数据 UniversalDetector.handleData(buf, offset, length); // 从文件读取数据,返回实际读取的长度 EncodingDetectorInputStream.readWithOneParameter(fd, buffer); // 以异步方法将数据写入文件 EncodingDetectorOutputStream.writeWithTreeParameter(fd, b, off, len); ``` ## 接口说明 `let detector: UniversalDetector = new UniversalDetector();` 1. 向检测器输入数据 `detector.handleData()` 2. 从InputStream获取内容的符号集 `UniversalDetector.detectCharset()` 3. 读取结束 `detector.dataEnd()` 4. 检测到的编码 `detector.getDetectedCharset()` 5. 重置 `detector.reset()` ## 兼容性 支持 OpenHarmony API version 8 及以上版本。 ## 目录结构 ``` |---- juniversalchardet | |---- entry # 示例代码文件夹 | |---- juniversalchardet # juniversalchardet库文件夹 | |----src | |----main | |----ets | |----prober # 检测器文件 | |----constextanalysis # 语境分析 | |----distributionanalysis # 分布分析 | |----statemachine # 业务处理 | |---- index.ets # 对外接口 | |---- README.md # 安装使用方法 ``` ## 贡献代码 使用过程中发现任何问题都可以提 [Issue] (https://gitee.com/openharmony-sig/juniversalchardet/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR] (https://gitee.com/openharmony-sig/juniversalchardet/pulls) 。 ## 开源协议 本项目基于 [MPL-1.1 License]( https://gitee.com/openharmony-sig/juniversalchardet/blob/master/LICENSE ) ,请自由地享受和参与开源。