Skip to content

Commit

Permalink
Switch from json-stream to byline.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns committed Jun 25, 2019
1 parent 951dd13 commit 57f6c0b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
54 changes: 23 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
"@types/request": "^2.47.1",
"@types/underscore": "^1.8.9",
"@types/ws": "^6.0.1",
"byline": "^5.0.0",
"execa": "1.0.0",
"isomorphic-ws": "^4.0.1",
"js-yaml": "^3.13.1",
"json-stream": "^1.0.0",
"jsonpath-plus": "^0.19.0",
"request": "^2.88.0",
"shelljs": "^0.8.2",
Expand All @@ -64,6 +64,7 @@
"ws": "^6.1.0"
},
"devDependencies": {
"@types/byline": "^4.2.31",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
"@types/mocha": "^5.2.7",
Expand Down
13 changes: 10 additions & 3 deletions src/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import JSONStream = require('json-stream');
import byline = require('byline');
import request = require('request');
import { KubeConfig } from './config';

Expand Down Expand Up @@ -55,8 +55,15 @@ export class Watch {
};
this.config.applyToRequest(requestOptions);

const stream = new JSONStream();
stream.on('data', (data) => callback(data.type, data.object));
const stream = byline.createStream();
stream.on('data', (line) => {
try {
const data = JSON.parse(line);
callback(data.type, data.object);
} catch (ignore) {
// ignore parse errors
}
});
const req = this.requestImpl.webRequest(requestOptions, (error, response, body) => {
if (error) {
done(error);
Expand Down

0 comments on commit 57f6c0b

Please sign in to comment.