@e-mc/request 0.7.20 → 0.7.22

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.
@@ -365,6 +365,7 @@ class HttpAdapter {
365
365
  this.terminate("No data received");
366
366
  return;
367
367
  }
368
+ dataLength = this.contentLength || (typeof this.pipeTo === 'string' ? (0, util_1.getSize)(this.pipeTo) : 0);
368
369
  result = encoding && !pipeline ? '' : null;
369
370
  }
370
371
  this.endResponse(result, dataLength, log);
@@ -377,12 +378,11 @@ class HttpAdapter {
377
378
  }
378
379
  endResponse(result, dataLength = 0, logging = this.state.log) {
379
380
  if (logging) {
380
- const messageUnit = this.dataTime && dataLength > 0 ? (0, util_1.getTransferRate)(dataLength, (0, types_1.convertTime)(process.hrtime.bigint() - this.dataTime, false) * 1000) : undefined;
381
381
  this.instance.writeTimeProcess('HTTP' + this.httpVersion, this.opts.statusMessage || this.uri.toString(), this.startTime, {
382
382
  type: 1024,
383
383
  queue: !!this.instance.host,
384
384
  titleBgColor: !result ? 'bgBlue' : undefined,
385
- messageUnit,
385
+ messageUnit: this.formatMibs(dataLength),
386
386
  messageUnitMinWidth: 9,
387
387
  delayTime: this.delayTime,
388
388
  bypassLog: module_1.hasLogType(32768)
@@ -494,6 +494,11 @@ class HttpAdapter {
494
494
  formatStatus(value, hint) {
495
495
  return value + ': ' + (hint || (0, util_1.fromStatusCode)(value)) + ` (${this.uri.toString()})`;
496
496
  }
497
+ formatMibs(dataLength) {
498
+ if (dataLength > 0 && this.dataTime) {
499
+ return (0, util_1.getTransferRate)(dataLength, Math.max(1, (0, types_1.convertTime)(process.hrtime.bigint() - this.dataTime, false) * 1000));
500
+ }
501
+ }
497
502
  close() {
498
503
  this.closed = true;
499
504
  this.instance.reset(this);
package/index.js CHANGED
@@ -1960,7 +1960,7 @@ class Request extends module_1.default {
1960
1960
  }
1961
1961
  }
1962
1962
  if (mibsTime) {
1963
- const unit = (Buffer.byteLength(buffer, encoding) * 8) / ((0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000);
1963
+ const unit = (Buffer.byteLength(buffer, encoding) * 8) / Math.max(1, (0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000);
1964
1964
  if (unit < 1) {
1965
1965
  messageUnit = Math.ceil(unit * 1000) + 'KiB/s';
1966
1966
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.7.20",
3
+ "version": "0.7.22",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.7.20",
24
- "@e-mc/types": "0.7.20",
23
+ "@e-mc/module": "0.7.22",
24
+ "@e-mc/types": "0.7.22",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "which": "^2.0.2"