ibm-cloud-sdk-core 2.17.3 → 2.17.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [2.17.4](https://github.com/IBM/node-sdk-core/compare/v2.17.3...v2.17.4) (2021-12-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * don't always convert bytes to text in streamToPromise ([#182](https://github.com/IBM/node-sdk-core/issues/182)) ([7fe261b](https://github.com/IBM/node-sdk-core/commit/7fe261b20f934cd3fde45acc69b9d4888836aa69))
7
+
1
8
  ## [2.17.3](https://github.com/IBM/node-sdk-core/compare/v2.17.2...v2.17.3) (2021-12-13)
2
9
 
3
10
 
@@ -54,7 +54,7 @@
54
54
  | [readCrTokenFile(filepath)](./ibm-cloud-sdk-core.readcrtokenfile.md) | |
55
55
  | [readExternalSources(serviceName)](./ibm-cloud-sdk-core.readexternalsources.md) | Read properties stored in external sources like Environment Variables, the credentials file, VCAP services, etc. and return them as an object. The keys of this object will have the service name prefix removed and will be converted to lower camel case.<!-- -->Only one source will be used at a time. |
56
56
  | [removeSuffix(str, suffix)](./ibm-cloud-sdk-core.removesuffix.md) | Remove a given suffix if it exists. |
57
- | [streamToPromise(stream)](./ibm-cloud-sdk-core.streamtopromise.md) | Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text Essentially a smaller version of concat-stream wrapped in a promise |
57
+ | [streamToPromise(stream)](./ibm-cloud-sdk-core.streamtopromise.md) | Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer or array of text chunks Essentially a smaller version of concat-stream wrapped in a promise |
58
58
  | [stripTrailingSlash(url)](./ibm-cloud-sdk-core.striptrailingslash.md) | |
59
59
  | [toLowerKeys(obj)](./ibm-cloud-sdk-core.tolowerkeys.md) | This function converts an object's keys to lower case. note: does not convert nested keys |
60
60
  | [validateInput(options, requiredOptions)](./ibm-cloud-sdk-core.validateinput.md) | |
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## streamToPromise() function
6
6
 
7
- Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text Essentially a smaller version of concat-stream wrapped in a promise
7
+ Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer or array of text chunks Essentially a smaller version of concat-stream wrapped in a promise
8
8
 
9
9
  <b>Signature:</b>
10
10
 
@@ -5139,7 +5139,7 @@
5139
5139
  {
5140
5140
  "kind": "Function",
5141
5141
  "canonicalReference": "ibm-cloud-sdk-core!streamToPromise:function(1)",
5142
- "docComment": "/**\n * Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text Essentially a smaller version of concat-stream wrapped in a promise\n *\n * @param stream - Optional stream param for when not bound to an existing stream instance. @return {Promise}\n */\n",
5142
+ "docComment": "/**\n * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer or array of text chunks Essentially a smaller version of concat-stream wrapped in a promise\n *\n * @param stream - Optional stream param for when not bound to an existing stream instance. @return {Promise}\n */\n",
5143
5143
  "excerptTokens": [
5144
5144
  {
5145
5145
  "kind": "Content",
@@ -360,7 +360,8 @@ export class RequestWrapper {
360
360
  let reqBuffer;
361
361
  try {
362
362
  if (isStream(data)) {
363
- reqBuffer = Buffer.from(yield streamToPromise(data));
363
+ const streamData = yield streamToPromise(data);
364
+ reqBuffer = Buffer.isBuffer(streamData) ? streamData : Buffer.from(streamData);
364
365
  }
365
366
  else if (data.toString && data.toString() !== '[object Object]' && !Array.isArray(data)) {
366
367
  // this handles pretty much any primitive that isnt a JSON object or array
@@ -16,7 +16,8 @@
16
16
  /// <reference types="node" />
17
17
  import { Stream } from 'stream';
18
18
  /**
19
- * Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text
19
+ * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer
20
+ * or array of text chunks
20
21
  * Essentially a smaller version of concat-stream wrapped in a promise
21
22
  *
22
23
  * @param {Stream} stream Optional stream param for when not bound to an existing stream instance.
@@ -14,7 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  /**
17
- * Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text
17
+ * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer
18
+ * or array of text chunks
18
19
  * Essentially a smaller version of concat-stream wrapped in a promise
19
20
  *
20
21
  * @param {Stream} stream Optional stream param for when not bound to an existing stream instance.
@@ -29,7 +30,7 @@ export function streamToPromise(stream) {
29
30
  results.push(result);
30
31
  })
31
32
  .on('end', () => {
32
- resolve(Buffer.isBuffer(results[0]) ? Buffer.concat(results).toString() : results);
33
+ resolve(Buffer.isBuffer(results[0]) ? Buffer.concat(results) : results);
33
34
  })
34
35
  .on('error', reject);
35
36
  });
@@ -1228,7 +1228,8 @@ export declare class BaseService {
1228
1228
  }
1229
1229
 
1230
1230
  /**
1231
- * Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text
1231
+ * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer
1232
+ * or array of text chunks
1232
1233
  * Essentially a smaller version of concat-stream wrapped in a promise
1233
1234
  *
1234
1235
  * @param {Stream} stream Optional stream param for when not bound to an existing stream instance.
@@ -411,22 +411,22 @@ var RequestWrapper = /** @class */ (function () {
411
411
  };
412
412
  RequestWrapper.prototype.gzipRequestBody = function (data, headers) {
413
413
  return __awaiter(this, void 0, void 0, function () {
414
- var contentSetToGzip, reqBuffer, _a, _b, err_1;
415
- return __generator(this, function (_c) {
416
- switch (_c.label) {
414
+ var contentSetToGzip, reqBuffer, streamData, err_1;
415
+ return __generator(this, function (_a) {
416
+ switch (_a.label) {
417
417
  case 0:
418
418
  contentSetToGzip = headers['Content-Encoding'] && headers['Content-Encoding'].toString().includes('gzip');
419
419
  if (!data || contentSetToGzip) {
420
420
  return [2 /*return*/, data];
421
421
  }
422
- _c.label = 1;
422
+ _a.label = 1;
423
423
  case 1:
424
- _c.trys.push([1, 5, , 6]);
424
+ _a.trys.push([1, 5, , 6]);
425
425
  if (!isstream_1.default(data)) return [3 /*break*/, 3];
426
- _b = (_a = Buffer).from;
427
426
  return [4 /*yield*/, stream_to_promise_1.streamToPromise(data)];
428
427
  case 2:
429
- reqBuffer = _b.apply(_a, [_c.sent()]);
428
+ streamData = _a.sent();
429
+ reqBuffer = Buffer.isBuffer(streamData) ? streamData : Buffer.from(streamData);
430
430
  return [3 /*break*/, 4];
431
431
  case 3:
432
432
  if (data.toString && data.toString() !== '[object Object]' && !Array.isArray(data)) {
@@ -436,10 +436,10 @@ var RequestWrapper = /** @class */ (function () {
436
436
  else {
437
437
  reqBuffer = Buffer.from(JSON.stringify(data));
438
438
  }
439
- _c.label = 4;
439
+ _a.label = 4;
440
440
  case 4: return [3 /*break*/, 6];
441
441
  case 5:
442
- err_1 = _c.sent();
442
+ err_1 = _a.sent();
443
443
  logger_1.default.error('Error converting request body to a buffer - data will not be compressed.');
444
444
  logger_1.default.debug(err_1);
445
445
  return [2 /*return*/, data];
@@ -16,7 +16,8 @@
16
16
  /// <reference types="node" />
17
17
  import { Stream } from 'stream';
18
18
  /**
19
- * Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text
19
+ * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer
20
+ * or array of text chunks
20
21
  * Essentially a smaller version of concat-stream wrapped in a promise
21
22
  *
22
23
  * @param {Stream} stream Optional stream param for when not bound to an existing stream instance.
@@ -16,7 +16,8 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  /**
19
- * Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text
19
+ * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer
20
+ * or array of text chunks
20
21
  * Essentially a smaller version of concat-stream wrapped in a promise
21
22
  *
22
23
  * @param {Stream} stream Optional stream param for when not bound to an existing stream instance.
@@ -31,7 +32,7 @@ function streamToPromise(stream) {
31
32
  results.push(result);
32
33
  })
33
34
  .on('end', function () {
34
- resolve(Buffer.isBuffer(results[0]) ? Buffer.concat(results).toString() : results);
35
+ resolve(Buffer.isBuffer(results[0]) ? Buffer.concat(results) : results);
35
36
  })
36
37
  .on('error', reject);
37
38
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "2.17.3",
3
+ "version": "2.17.4",
4
4
  "description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
5
5
  "main": "index.js",
6
6
  "module": "./es/index.js",
@@ -5139,7 +5139,7 @@
5139
5139
  {
5140
5140
  "kind": "Function",
5141
5141
  "canonicalReference": "ibm-cloud-sdk-core!streamToPromise:function(1)",
5142
- "docComment": "/**\n * Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text Essentially a smaller version of concat-stream wrapped in a promise\n *\n * @param stream - Optional stream param for when not bound to an existing stream instance. @return {Promise}\n */\n",
5142
+ "docComment": "/**\n * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer or array of text chunks Essentially a smaller version of concat-stream wrapped in a promise\n *\n * @param stream - Optional stream param for when not bound to an existing stream instance. @return {Promise}\n */\n",
5143
5143
  "excerptTokens": [
5144
5144
  {
5145
5145
  "kind": "Content",