Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
be1b905d
Commit
be1b905d
authored
Mar 23, 2016
by
Antoor
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21 from antoor/v1.0.1
优化数据截取处理算法
parents
1214be30
dd23d134
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
request.js
modules/request.js
+8
-2
No files found.
modules/request.js
View file @
be1b905d
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment