@@ -17,7 +17,7 @@ import * as url from 'url';
17
17
import * as http from 'http' ;
18
18
import * as https from 'https' ;
19
19
import * as zlib from 'zlib' ;
20
- import { pipeline , Readable } from 'stream' ;
20
+ import { Readable } from 'stream' ;
21
21
import * as collectorTypes from '../../types' ;
22
22
import { CollectorExporterNodeBase } from './CollectorExporterNodeBase' ;
23
23
import { CollectorExporterNodeConfigBase } from '.' ;
@@ -83,26 +83,24 @@ export function sendWithHttp<ExportItem, ServiceRequest>(
83
83
} ) ;
84
84
85
85
if ( compress ) {
86
- const dataStream = Readable . from ( data ) ;
87
- pipeline ( dataStream , gzip , req , onGzipError ( onError ) ) ;
86
+ const dataStream = readableFromBuffer ( data ) ;
87
+ dataStream . on ( 'error' , onError )
88
+ . pipe ( gzip ) . on ( 'error' , onError )
89
+ . pipe ( req ) ;
88
90
} else {
89
91
req . write ( data ) ;
90
92
req . end ( ) ;
91
93
}
92
94
}
93
95
94
- function onGzipError ( onError : ( error : collectorTypes . CollectorExporterError ) => void ) {
95
- return ( err : NodeJS . ErrnoException | null ) => {
96
- const error = new collectorTypes . CollectorExporterError (
97
- err ?. message ,
98
- 500 ,
99
- 'Compressing the request body for collector exporter failed.'
100
- ) ;
101
- onError ( error )
102
- }
96
+ function readableFromBuffer ( buff : string | Buffer ) : Readable {
97
+ const readable = new Readable ( ) ;
98
+ readable . push ( buff ) ;
99
+ readable . push ( null ) ;
100
+
101
+ return readable ;
103
102
}
104
103
105
-
106
104
export function createHttpAgent (
107
105
config : CollectorExporterNodeConfigBase
108
106
) : http . Agent | https . Agent | undefined {
0 commit comments