Commit e71f22d0 authored by Medicean's avatar Medicean

(Enhance:Core) 优化解码器

1. 移除解码器 `decode_str` 方法, 统一调用 `decode_buff` 方法
2. 解码器解码后, 增加猜解字符编码流程
parent 9ff2d35f
......@@ -2,6 +2,16 @@
> 有空会补补BUG、添添新功能。
> 同时也欢迎大家的参与!感谢各位朋友的支持! .TAT.
## `v(2.1.3)`
### 核心模块
* 移除解码器 `decode_str` 方法, 统一调用 `decode_buff` 方法
> `decode_str` 其实相当于是 `decode_buff` 执行后调用了 `toString`
* 解码器解码后, 增加猜解字符编码流程
## 2019/05/13 `v(2.1.2)`
### 核心模块
......
{
"name": "antsword",
"version": "2.1.2",
"version": "2.1.2.1",
"description": "中国蚁剑是一款跨平台的开源网站管理工具",
"main": "app.js",
"dependencies": {
......
......@@ -8,10 +8,7 @@ module.exports = {
asoutput: () => {
return ``.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return data;
},
decode_buff: (data) => {
return data;
decode_buff: (buff) => {
return buff;
}
}
\ No newline at end of file
......@@ -8,10 +8,7 @@ module.exports = {
asoutput: () => {
return ``.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return data;
},
decode_buff: (data) => {
return data;
decode_buff: (buff) => {
return buff;
}
}
\ No newline at end of file
......@@ -261,10 +261,14 @@ class Base {
antSword['ipcRenderer']
// 请求完毕返回数据{text,buff}
.once(`request-${hash}`, (event, ret) => {
let buff = this.__decoder__[this.__opts__['decoder']||'default'].decode_buff(ret['buff'], ext);
let encoding = antSword.Decodes.detectEncoding(buff, {defaultEncoding: "unknown"});
encoding = encoding != "unknown" ? encoding : this.__opts__['encode'];
let text = antSword.Decodes.decode(buff, encoding);
return res({
'encoding': ret['encoding'] || "",
'text': this.__decoder__[this.__opts__['decoder']||'default'].decode_str(ret['text'], ext),
'buff': this.__decoder__[this.__opts__['decoder']||'default'].decode_buff(ret['buff'], ext)
'encoding': encoding || "",
'text': text,
'buff': buff,
});
})
// HTTP请求返回字节流
......
......@@ -8,9 +8,6 @@ module.exports = {
asoutput: () => {
return ``.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return data;
},
decode_buff: (data) => {
return data;
}
......
......@@ -14,20 +14,12 @@ module.exports = {
}
`.replace(/\n\s+/g, '');
},
/**
* 解码字符串
* @param {string} data 要被解码的字符串
* @returns {string} 解码后的字符串
*/
decode_str: (data) => {
return Buffer.from(data, 'base64').toString();
},
/**
* 解码 Buffer
* @param {string} data 要被解码的 Buffer
* @returns {string} 解码后的 Buffer
* @param {Buffer} buff 要被解码的 Buffer
* @returns {Buffer} 解码后的 Buffer
*/
decode_buff: (data) => {
return Buffer.from(data.toString(), 'base64');
decode_buff: (buff) => {
return Buffer.from(buff.toString(), 'base64');
}
}
\ No newline at end of file
......@@ -14,20 +14,12 @@ module.exports = {
}
`.replace(/\n\s+/g, '');
},
/**
* 解码字符串
* @param {string} data 要被解码的字符串
* @returns {string} 解码后的字符串
*/
decode_str: (data) => {
return data;
},
/**
* 解码 Buffer
* @param {string} data 要被解码的 Buffer
* @returns {string} 解码后的 Buffer
* @param {Buffer} buff 要被解码的 Buffer
* @returns {Buffer} 解码后的 Buffer
*/
decode_buff: (data) => {
return data;
decode_buff: (buff) => {
return buff;
}
}
\ No newline at end of file
......@@ -20,10 +20,7 @@ module.exports = {
}
`.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return rot13encode(data);
},
decode_buff: (data) => {
return Buffer.from(rot13encode(data.toString()));
decode_buff: (buff) => {
return Buffer.from(rot13encode(buff.toString()));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment