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
32 lines (27 loc) · 907 Bytes
/
submitSync.ts
File metadata and controls
32 lines (27 loc) · 907 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
32
import { NodeSubmissionAdapter } from './submission/NodeSubmissionAdapter';
import { SubmissionRequest } from './submission/SubmissionRequest';
import * as stream from 'stream';
import { StringDecoder } from 'string_decoder';
let decoder = new StringDecoder('utf8');
let strings: string[] = [];
let jsonStream = new stream.Writable();
jsonStream._write = (chunk: Buffer | string, encoding: string, next: Function) => {
strings.push(decoder.write(<Buffer>chunk));
next();
};
jsonStream.on('finish', () => {
let json = strings.join('');
let request: SubmissionRequest = JSON.parse(json);
let adapter = new NodeSubmissionAdapter();
adapter.sendRequest(request, (status, message, data, headers) => {
let result = {
status,
message,
data,
headers
};
process.stdout.write(JSON.stringify(result));
process.exit(0);
});
});
process.stdin.pipe(jsonStream);