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