oipage 1.7.0-alpha.6 → 1.7.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * json of OIPage v1.7.0-alpha.6
2
+ * json of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {reader} = require("../reader/index.js");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * logform of OIPage v1.7.0-alpha.6
2
+ * logform of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {linelog} = require("../cmdlog/index.js");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * reader of OIPage v1.7.0-alpha.6
2
+ * reader of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -5,6 +5,8 @@ interface resType {
5
5
  */
6
6
  status: number
7
7
 
8
+ type: "string" | "json" | "binary"
9
+
8
10
  /**
9
11
  * 响应体
10
12
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * remote of OIPage v1.7.0-alpha.6
2
+ * remote of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -21,17 +21,47 @@ function remote(method, url, headers, param) {
21
21
  method,
22
22
  headers
23
23
  }, (res) => {
24
- res.setEncoding("utf8");
25
24
 
26
- let data = "";
25
+ let _temp = (res.headers["content-type"] + "").split(";");
26
+
27
+ // 数据类型
28
+ let contentType = _temp[0];
29
+
30
+ // 数据编码
31
+ let contentEncoding = "";
32
+ if (_temp[1]) contentEncoding = _temp[1].replace("charset=", "")
33
+ else res.setEncoding("binary"); // 二进制
34
+
35
+ const chunks = []; // 用于存储接收到的数据块
36
+ let size = 0; // 用于跟踪接收到的数据总量
37
+
27
38
  res.on('data', (chunk) => {
28
- data += chunk;
39
+ chunks.push(chunk); // 将接收到的数据块添加到数组中
40
+ size += chunk.length; // 更新已接收的数据总量
29
41
  });
42
+
30
43
  res.on('end', () => {
44
+ let data = Buffer.concat(chunks, size); // 将所有数据块合并为一个Buffer
45
+ let type = "binary"
46
+
47
+ // 如果有编码,认为是文本
48
+ if (contentEncoding) {
49
+ data = data.toString('utf8');
50
+ type = "string";
51
+ }
52
+
53
+ // JSON文件
54
+ if (contentType === "application/json") {
55
+ try {
56
+ data = JSON.parse(data);
57
+ type = "json";
58
+ } catch (e) { }
59
+ }
31
60
 
32
61
  resolve({
33
62
  status: res.statusCode,
34
- data: data.toString('utf8'),
63
+ type,
64
+ data,
35
65
  headers: res.headers
36
66
  });
37
67
  });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.7.0-alpha.6
2
+ * throttle of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "1.7.0-alpha.6",
3
+ "version": "1.7.0-alpha.7",
4
4
  "description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
5
5
  "sideEffects": false,
6
6
  "typings": "./types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -17,6 +17,8 @@ import "../nodejs/remote/index";
17
17
  declare module "oipage/nodejs/remote/index.js" {}
18
18
  import "../nodejs/throttle/index";
19
19
  declare module "oipage/nodejs/throttle/index.js" {}
20
+ import "../web/XMLHttpRequest/index";
21
+ declare module "oipage/web/XMLHttpRequest/index.js" {}
20
22
  import "../web/animation/index";
21
23
  declare module "oipage/web/animation/index.js" {}
22
24
  import "../web/format/index";
@@ -33,5 +35,3 @@ import "../web/style/index";
33
35
  declare module "oipage/web/style/index.js" {}
34
36
  import "../web/throttle/index";
35
37
  declare module "oipage/web/throttle/index.js" {}
36
- import "../web/XMLHttpRequest/index";
37
- declare module "oipage/web/XMLHttpRequest/index.js" {}
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * XMLHttpRequest of OIPage v1.7.0-alpha.6
2
+ * XMLHttpRequest of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.7.0-alpha.6
2
+ * animation of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * format of OIPage v1.7.0-alpha.6
2
+ * format of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
package/web/json/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * json of OIPage v1.7.0-alpha.6
2
+ * json of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  import {reader} from "../reader/index.js";
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * onReady of OIPage v1.7.0-alpha.6
2
+ * onReady of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * performChunk of OIPage v1.7.0-alpha.6
2
+ * performChunk of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * reader of OIPage v1.7.0-alpha.6
2
+ * reader of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * style of OIPage v1.7.0-alpha.6
2
+ * style of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.7.0-alpha.6
2
+ * throttle of OIPage v1.7.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5