Commit be1b905d authored by Antoor's avatar Antoor

Merge pull request #21 from antoor/v1.0.1

优化数据截取处理算法
parents 1214be30 dd23d134
......@@ -49,24 +49,30 @@ class Request {
// 数据转换二进制处理
res.setEncoding('binary');
res.data = '';
let foundTagS = false;
let foundTagE = false;
res.on('data', (chunk) => {
let temp = '';
// 如果包含前后截断,则截取中间
if (chunk.indexOf([tag_s]) >= 0 && chunk.lastIndexOf(tag_e) >= 0) {
if (chunk.indexOf(tag_s) >= 0 && chunk.lastIndexOf(tag_e) >= 0) {
const index_s = chunk.indexOf(tag_s);
const index_e = chunk.lastIndexOf(tag_e);
temp = chunk.substr(index_s + tag_s.length, index_e - index_s - tag_e.length);
foundTagS = foundTagE = true;
}
// 如果只包含前截断,则截取后边
else if (chunk.indexOf(tag_s) >= 0 && chunk.lastIndexOf(tag_e) === -1) {
temp = chunk.split(tag_s)[1];
foundTagS = true;
}
// 如果只包含后截断,则截取前边
else if (chunk.indexOf(tag_s) === -1 && chunk.lastIndexOf(tag_e) >= 0) {
temp = chunk.split(tag_e)[0];
foundTagE = true;
}
// 如果有没有,那就是中途迷路的数据啦 ^.^
else {
else if (foundTagS && !foundTagE) {
temp = chunk;
}
......
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