Skip to content

Commit

Permalink
修复 nodejs 6.x Conf 报错
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Feb 7, 2021
1 parent 546471f commit 99ce398
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
6 changes: 3 additions & 3 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,10 @@ var selectJsonOpt = {

function selectObjectContentStream() {
// 查询 JSON
var selectStream = cos.selectObjectContentStream({
...selectJsonOpt,
var opt = Object.assign({
// DataType: 'raw',
}, function (err, data) {
}, selectJsonOpt);
var selectStream = cos.selectObjectContentStream(opt, function (err, data) {
console.log(err || data);
});
var outFile = './result.txt';
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-nodejs-sdk-v5",
"version": "2.9.5",
"version": "2.9.6",
"description": "cos nodejs sdk v5",
"main": "index.js",
"types": "types",
Expand Down Expand Up @@ -31,7 +31,7 @@
"homepage": "https://github.com/tencentyun/cos-nodejs-sdk-v5#readme",
"dependencies": {
"@types/node": "^14.14.20",
"conf": "^7.1.2",
"conf": "^9.0.0",
"mime-types": "^2.1.24",
"request": "^2.88.2",
"xml2js": "^0.4.19"
Expand All @@ -40,5 +40,8 @@
"mocha": "^4.0.1",
"nyc": "^15.1.0",
"qcloud-cos-sts": "^3.0.0"
},
"engines": {
"node": ">= 6"
}
}
17 changes: 3 additions & 14 deletions sdk/select-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ SelectStream.prototype = {
*/
processChunk(chunk, encoding, callback) {
Object.assign(this, {
chunk: Buffer.concat(
[this.chunk, chunk],
this.chunk.length + chunk.length,
),
chunk: Buffer.concat([this.chunk, chunk], this.chunk.length + chunk.length),
encoding,
callback,
});
Expand Down Expand Up @@ -78,17 +75,9 @@ SelectStream.prototype = {
var offset = 0;
while (offset < this.headerLength) {
var headerNameLength = this.chunk[offset] * 1;
var headerName = this.chunk.toString(
'ascii',
offset + 1,
offset + 1 + headerNameLength,
);
var headerName = this.chunk.toString('ascii', offset + 1, offset + 1 + headerNameLength);
var headerValueLength = this.chunk.readInt16BE(offset + headerNameLength + 2);
var headerValue = this.chunk.toString(
'ascii',
offset + headerNameLength + 4,
offset + headerNameLength + 4 + headerValueLength,
);
var headerValue = this.chunk.toString('ascii', offset + headerNameLength + 4, offset + headerNameLength + 4 + headerValueLength);
header[headerName] = headerValue;
offset += headerNameLength + 4 + headerValueLength;
}
Expand Down
5 changes: 2 additions & 3 deletions sdk/session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var Conf = require('conf');
var util = require('./util');

// 按照文件特征值,缓存 UploadId
var cacheKey = 'cos_sdk_upload_cache';
var expires = 30 * 24 * 3600;
Expand All @@ -12,6 +10,7 @@ var getCache = function () {
var val, opt = {configName: 'cos-nodejs-sdk-v5-storage'};
if (this.options.ConfCwd) opt.cwd = this.options.ConfCwd;
try {
var Conf = require('conf');
store = new Conf(opt);
val = store.get(cacheKey);
} catch (e) {}
Expand All @@ -20,7 +19,7 @@ var getCache = function () {
};
var setCache = function () {
try {
localStorage.setItem(cacheKey, JSON.stringify(cache))
store.set(cacheKey, cache);
} catch (e) {
}
};
Expand Down

0 comments on commit 99ce398

Please sign in to comment.