@jsforce/jsforce-node 3.10.11 → 3.10.12-dev.1
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.
- package/lib/request-helper.js +6 -0
- package/lib/util/stream.js +28 -3
- package/package.json +1 -1
package/lib/request-helper.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.executeWithTimeout = exports.performRedirectRequest = exports.isRedirect
|
|
|
7
7
|
const stream_1 = require("stream");
|
|
8
8
|
const stream_2 = require("./util/stream");
|
|
9
9
|
const form_data_1 = __importDefault(require("form-data"));
|
|
10
|
+
const logger_1 = require("./util/logger");
|
|
11
|
+
const logger = (0, logger_1.getLogger)('request-helper');
|
|
10
12
|
/**
|
|
11
13
|
*
|
|
12
14
|
*/
|
|
@@ -27,7 +29,11 @@ function createHttpRequestHandlerStreams(req, options = {}) {
|
|
|
27
29
|
}
|
|
28
30
|
duplex.on('response', async (res) => {
|
|
29
31
|
if (duplex.listenerCount('complete') > 0) {
|
|
32
|
+
logger.debug(`Processing response, status=${res.statusCode}`);
|
|
33
|
+
const start = Date.now();
|
|
30
34
|
const resBody = await (0, stream_2.readAll)(duplex, options.encoding);
|
|
35
|
+
logger.debug(`Response body read: ${(resBody.length / 1024 / 1024).toFixed(1)}MB ` +
|
|
36
|
+
`in ${Date.now() - start}ms`);
|
|
31
37
|
duplex.emit('complete', {
|
|
32
38
|
...res,
|
|
33
39
|
body: resBody,
|
package/lib/util/stream.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.concatStreamsAsDuplex = exports.readAll = exports.createLazyStream = void 0;
|
|
4
4
|
const stream_1 = require("stream");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const logger = (0, logger_1.getLogger)('stream');
|
|
5
7
|
function createLazyStream() {
|
|
6
8
|
const ins = new stream_1.PassThrough();
|
|
7
9
|
const outs = new stream_1.PassThrough();
|
|
@@ -19,30 +21,53 @@ function createLazyStream() {
|
|
|
19
21
|
exports.createLazyStream = createLazyStream;
|
|
20
22
|
class MemoryWriteStream extends stream_1.Writable {
|
|
21
23
|
_chunks;
|
|
24
|
+
_totalBytes;
|
|
22
25
|
constructor() {
|
|
23
26
|
super();
|
|
24
27
|
this._chunks = [];
|
|
28
|
+
this._totalBytes = 0;
|
|
25
29
|
}
|
|
26
30
|
_write(chunk, encoding, callback) {
|
|
27
31
|
this._chunks.push(chunk);
|
|
32
|
+
this._totalBytes += chunk.length;
|
|
33
|
+
// Log progress every 10MB
|
|
34
|
+
if (this._totalBytes % (10 * 1024 * 1024) < chunk.length) {
|
|
35
|
+
logger.debug(`MemoryWriteStream: received ${this._chunks.length} chunks, ` +
|
|
36
|
+
`${(this._totalBytes / 1024 / 1024).toFixed(1)}MB total`);
|
|
37
|
+
}
|
|
28
38
|
callback();
|
|
29
39
|
}
|
|
30
40
|
_writev(data, callback) {
|
|
31
41
|
for (const { chunk } of data) {
|
|
32
42
|
this._chunks.push(chunk);
|
|
43
|
+
this._totalBytes += chunk.length;
|
|
33
44
|
}
|
|
45
|
+
logger.debug(`MemoryWriteStream._writev: received ${data.length} chunks in batch`);
|
|
34
46
|
callback();
|
|
35
47
|
}
|
|
36
48
|
toString(encoding = 'utf-8') {
|
|
37
|
-
|
|
49
|
+
logger.debug(`MemoryWriteStream.toString: concatenating ${this._chunks.length} chunks, ` +
|
|
50
|
+
`${(this._totalBytes / 1024 / 1024).toFixed(1)}MB`);
|
|
51
|
+
const start = Date.now();
|
|
52
|
+
const result = Buffer.concat(this._chunks).toString(encoding);
|
|
53
|
+
logger.debug(`MemoryWriteStream.toString: completed in ${Date.now() - start}ms`);
|
|
54
|
+
return result;
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
async function readAll(rs, encoding = 'utf-8') {
|
|
58
|
+
logger.debug('readAll: starting to read stream');
|
|
59
|
+
const start = Date.now();
|
|
41
60
|
return new Promise((resolve, reject) => {
|
|
42
61
|
const ws = new MemoryWriteStream();
|
|
43
|
-
rs.on('error',
|
|
62
|
+
rs.on('error', (err) => {
|
|
63
|
+
logger.error(`readAll: stream error: ${(err).message}`);
|
|
64
|
+
reject(err);
|
|
65
|
+
})
|
|
44
66
|
.pipe(ws)
|
|
45
|
-
.on('finish', () =>
|
|
67
|
+
.on('finish', () => {
|
|
68
|
+
logger.debug(`readAll: stream finished in ${Date.now() - start}ms`);
|
|
69
|
+
resolve(ws.toString(encoding));
|
|
70
|
+
});
|
|
46
71
|
});
|
|
47
72
|
}
|
|
48
73
|
exports.readAll = readAll;
|