@google-cloud/nodejs-common 2.0.1-alpha → 2.0.3-alpha

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.0.1-alpha",
3
+ "version": "2.0.3-alpha",
4
4
  "description": "A NodeJs common library for solutions based on Cloud Functions",
5
5
  "author": "Google Inc.",
6
6
  "license": "Apache-2.0",
@@ -98,7 +98,7 @@ class StorageFile {
98
98
  stream.on('data', (chunk) => void chunks.push(chunk));
99
99
  stream.on('end', () => {
100
100
  console.log(`Get [${this.fileName}] from ${start} to ${end}`);
101
- resolve(chunks.join(''));
101
+ resolve(Buffer.concat(chunks).toString());
102
102
  });
103
103
  stream.on('error', (error) => void reject(error));
104
104
  });
@@ -124,9 +124,12 @@ class StorageFile {
124
124
  checkPoint = Math.max(start, end - possibleLineBreakRange + 1);
125
125
  }
126
126
  const content = await this.loadContent(checkPoint, end);
127
- const index = Buffer.from(content).lastIndexOf(LINE_BREAKER);
127
+ let i = 0;
128
+ while (content.charCodeAt(i) === 0xFFFD) i++;
129
+ const cleanedContent = i > 0 ? content.slice(i) : content;
130
+ const index = Buffer.from(cleanedContent).lastIndexOf(LINE_BREAKER);
128
131
  if (index >= 0) {
129
- return checkPoint + index;
132
+ return checkPoint + i + index;
130
133
  }
131
134
  if (checkPoint > start) {
132
135
  return this.getLastLineBreaker(
@@ -252,3 +255,4 @@ module.exports = {
252
255
  LINE_BREAKER,
253
256
  DEFAULT_SPLIT_SIZE,
254
257
  };
258
+