Skip to content

Commit 99ce398

Browse files
committed
修复 nodejs 6.x Conf 报错
1 parent 546471f commit 99ce398

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

demo/demo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,10 @@ var selectJsonOpt = {
987987

988988
function selectObjectContentStream() {
989989
// 查询 JSON
990-
var selectStream = cos.selectObjectContentStream({
991-
...selectJsonOpt,
990+
var opt = Object.assign({
992991
// DataType: 'raw',
993-
}, function (err, data) {
992+
}, selectJsonOpt);
993+
var selectStream = cos.selectObjectContentStream(opt, function (err, data) {
994994
console.log(err || data);
995995
});
996996
var outFile = './result.txt';

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-nodejs-sdk-v5",
3-
"version": "2.9.5",
3+
"version": "2.9.6",
44
"description": "cos nodejs sdk v5",
55
"main": "index.js",
66
"types": "types",
@@ -31,7 +31,7 @@
3131
"homepage": "https://github.com/tencentyun/cos-nodejs-sdk-v5#readme",
3232
"dependencies": {
3333
"@types/node": "^14.14.20",
34-
"conf": "^7.1.2",
34+
"conf": "^9.0.0",
3535
"mime-types": "^2.1.24",
3636
"request": "^2.88.2",
3737
"xml2js": "^0.4.19"
@@ -40,5 +40,8 @@
4040
"mocha": "^4.0.1",
4141
"nyc": "^15.1.0",
4242
"qcloud-cos-sts": "^3.0.0"
43+
},
44+
"engines": {
45+
"node": ">= 6"
4346
}
4447
}

sdk/select-stream.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ SelectStream.prototype = {
2424
*/
2525
processChunk(chunk, encoding, callback) {
2626
Object.assign(this, {
27-
chunk: Buffer.concat(
28-
[this.chunk, chunk],
29-
this.chunk.length + chunk.length,
30-
),
27+
chunk: Buffer.concat([this.chunk, chunk], this.chunk.length + chunk.length),
3128
encoding,
3229
callback,
3330
});
@@ -78,17 +75,9 @@ SelectStream.prototype = {
7875
var offset = 0;
7976
while (offset < this.headerLength) {
8077
var headerNameLength = this.chunk[offset] * 1;
81-
var headerName = this.chunk.toString(
82-
'ascii',
83-
offset + 1,
84-
offset + 1 + headerNameLength,
85-
);
78+
var headerName = this.chunk.toString('ascii', offset + 1, offset + 1 + headerNameLength);
8679
var headerValueLength = this.chunk.readInt16BE(offset + headerNameLength + 2);
87-
var headerValue = this.chunk.toString(
88-
'ascii',
89-
offset + headerNameLength + 4,
90-
offset + headerNameLength + 4 + headerValueLength,
91-
);
80+
var headerValue = this.chunk.toString('ascii', offset + headerNameLength + 4, offset + headerNameLength + 4 + headerValueLength);
9281
header[headerName] = headerValue;
9382
offset += headerNameLength + 4 + headerValueLength;
9483
}

sdk/session.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
var Conf = require('conf');
21
var util = require('./util');
3-
42
// 按照文件特征值,缓存 UploadId
53
var cacheKey = 'cos_sdk_upload_cache';
64
var expires = 30 * 24 * 3600;
@@ -12,6 +10,7 @@ var getCache = function () {
1210
var val, opt = {configName: 'cos-nodejs-sdk-v5-storage'};
1311
if (this.options.ConfCwd) opt.cwd = this.options.ConfCwd;
1412
try {
13+
var Conf = require('conf');
1514
store = new Conf(opt);
1615
val = store.get(cacheKey);
1716
} catch (e) {}
@@ -20,7 +19,7 @@ var getCache = function () {
2019
};
2120
var setCache = function () {
2221
try {
23-
localStorage.setItem(cacheKey, JSON.stringify(cache))
22+
store.set(cacheKey, cache);
2423
} catch (e) {
2524
}
2625
};

0 commit comments

Comments
 (0)