@google-cloud/nodejs-common 2.4.1 → 2.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google-cloud/nodejs-common",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "A NodeJs common library for solutions based on Cloud Functions",
5
5
  "author": "Google Inc.",
6
6
  "license": "Apache-2.0",
@@ -66,7 +66,6 @@ class RestSearchStreamTransform extends Transform {
66
66
  if (endIndex > -1) {
67
67
  this.chunks.push(chunk);
68
68
  const rawString = Buffer.concat(this.chunks).toString();
69
- const startIndex = rawString.indexOf(START_TAG) + START_TAG.length;
70
69
  const maskIndex = rawString.lastIndexOf(FIELD_MASK_TAG);
71
70
  if (!this.processFn) {
72
71
  const fieldMask = rawString
@@ -82,11 +81,18 @@ class RestSearchStreamTransform extends Transform {
82
81
  this.processFn = processFn;
83
82
  }
84
83
  }
85
- const resultsWithTailing = rawString.substring(startIndex, maskIndex);
86
- const results = resultsWithTailing.substring(
87
- 0, resultsWithTailing.lastIndexOf(','));
88
- const rows = JSON.parse(results);
89
- const data = rows.map(this.processFn).join('\n') + '\n';
84
+ let rows, data;
85
+ if (rawString.indexOf(START_TAG) === -1) { // no 'results'
86
+ rows = [];
87
+ data = '';
88
+ } else {
89
+ const startIndex = rawString.indexOf(START_TAG) + START_TAG.length;
90
+ const resultsWithTailing = rawString.substring(startIndex, maskIndex);
91
+ const results = resultsWithTailing.substring(
92
+ 0, resultsWithTailing.lastIndexOf(','));
93
+ rows = JSON.parse(results);
94
+ data = rows.map(this.processFn).join('\n') + '\n';
95
+ }
90
96
  // Clear cached chunks.
91
97
  this.chunks = [latest.subarray(latest.indexOf(END_TAG) + END_TAG.length)];
92
98