Skip to content

Commit a34e8f9

Browse files
authored
Merge pull request kubernetes-client#289 from brendandburns/stream
Switch from json-stream to byline.
2 parents 951dd13 + 57f6c0b commit a34e8f9

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

package-lock.json

Lines changed: 23 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
"@types/request": "^2.47.1",
5353
"@types/underscore": "^1.8.9",
5454
"@types/ws": "^6.0.1",
55+
"byline": "^5.0.0",
5556
"execa": "1.0.0",
5657
"isomorphic-ws": "^4.0.1",
5758
"js-yaml": "^3.13.1",
58-
"json-stream": "^1.0.0",
5959
"jsonpath-plus": "^0.19.0",
6060
"request": "^2.88.0",
6161
"shelljs": "^0.8.2",
@@ -64,6 +64,7 @@
6464
"ws": "^6.1.0"
6565
},
6666
"devDependencies": {
67+
"@types/byline": "^4.2.31",
6768
"@types/chai": "^4.1.6",
6869
"@types/chai-as-promised": "^7.1.0",
6970
"@types/mocha": "^5.2.7",

src/watch.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import JSONStream = require('json-stream');
1+
import byline = require('byline');
22
import request = require('request');
33
import { KubeConfig } from './config';
44

@@ -55,8 +55,15 @@ export class Watch {
5555
};
5656
this.config.applyToRequest(requestOptions);
5757

58-
const stream = new JSONStream();
59-
stream.on('data', (data) => callback(data.type, data.object));
58+
const stream = byline.createStream();
59+
stream.on('data', (line) => {
60+
try {
61+
const data = JSON.parse(line);
62+
callback(data.type, data.object);
63+
} catch (ignore) {
64+
// ignore parse errors
65+
}
66+
});
6067
const req = this.requestImpl.webRequest(requestOptions, (error, response, body) => {
6168
if (error) {
6269
done(error);

0 commit comments

Comments
 (0)