forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmitSync.ts
More file actions
31 lines (25 loc) · 809 Bytes
/
submitSync.ts
File metadata and controls
31 lines (25 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { NodeSubmissionRequest, submitRequest } from './submission/NodeSubmissionRequest';
import * as stream from 'stream';
import { StringDecoder } from 'string_decoder';
var decoder = new StringDecoder('utf8');
var strings: string[] = [];
var jsonStream = new stream.Writable();
jsonStream._write = (chunk: Buffer|string, encoding: string, next: Function) => {
strings.push(decoder.write(<Buffer>chunk));
next();
};
jsonStream.on("finish", () => {
var json = strings.join("");
var request:NodeSubmissionRequest = JSON.parse(json);
submitRequest(request, (status, message, data, headers) => {
var result = {
status,
message,
data,
headers
};
process.stdout.write(JSON.stringify(result));
process.exit(0);
});
});
process.stdin.pipe(jsonStream);