pgm-utils
Version:
A PGM Utils
120 lines (94 loc) • 2.88 kB
Markdown
# PGMUtils
#### 介绍
解析 pgm、生成 pgm 的工具包
#### 版本记录
| 版本号 | 更新内容 | 更新人 |
| ------ | -------------------- | ---------- |
| 1.0.0 | pgm 解析、生成工具包 | CorrineCao |
#### 安装教程
1. npm install pgm-utils
2. yarn add pgm-utils
#### 使用说明
1. 解析 pgm 为 ImageData
```
<Upload
customRequest={async (info: any) => {
const { file: originFileObj } = info;
if (originFileObj.name.endsWith('.pgm')) {
const pgmImg: ImageData = await PGMUtils.PGMTool.getImageDataByPGMBlob(originFileObj);
}
}}
>
<Button type="primary">上传解析pgm文件</Button>
</Upload>
```
2. 通过 ImageData 生成 pgm
```
const pgmBlob: Uint8Array = PGMUtils.PGMTool.getPGMByImageData(imageData);
```
3. 解压并解析带有 pgm、yaml、json 文件的格式的 zip 文件
```
<Upload
customRequest={async (info: any) => {
const { file: originFileObj } = info;
if (info.file.name.endsWith('.zip')) {
if (originFileObj) {
PGMUtils.DeflateTool.inflatePKG(originFileObj).then((res) => {
console.log('>>>>res:', res);
});
}
}
}}
>
<Button type="primary">上传解析压缩的pgm文件</Button>
</Upload>
```
4. 压缩文件并返回文件对象,支持直接导出 zip 格式文件类型,可以包括 json、pgm、yaml 文件格式,可以自定义文件名
```
// 引入
import PGMUtils from 'pgm-utils';
// 使用
const record: Record<string, any> = {};
record['test.json'] = {
name: 'test',
...
}; // 引入json文件
record['test.pgm'] = ImageData; // 引入pgm文件
record['test.yaml'] = {
name: 'test',
origin: [0,0,0],
...
}
PGMUtils.DeflateTool.deflatePKG(record, '压缩文件名');
```
5. 直接压缩并获取 zip 类型的 File 文件
```
const file = await PGMUtils.DeflateTool.getDeflatePKG(record, '压缩文件名');
```
6. 压缩并直接导出 zip 文件
```
PGMUtils.DeflateTool.exportDeflatePKG(record, '压缩文件名');
```
7. 获取上传 yaml 文件的内容
```
<Upload
customRequest={async (info: any) => {
const { file: originFileObj } = info;
if (originFileObj.name.endsWith('.yaml')) {
const yamlInfo = await PGMUtils.YamlTool.getYamlInfoByBlob(originFileObj);
}
}}
>
<Button type="primary">上传yaml文件</Button>
</Upload>
```
8. 通过字符串数据转换成 yaml 文件对象数据
```
const yamlInfo = PGMUtils.YamlTool.getYamlInfoByContent(yamlContent);
```
9. 通过 yaml 对象数据转换成 string 类型数据
```
const yamlContent = PGMUtils.YamlTool.getContentByYamlInfo(yamlInfo);
```
#### 参与贡献
CorrineCao