9
9
10
10
import type { Writable } from 'stream' ;
11
11
12
- type MightBeFlushable = { flush ?: ( ) => void } ;
12
+ type MightBeFlushable = {
13
+ flush ?: ( ) => void ,
14
+ flushHeaders ?: ( ) => void , // Legacy
15
+ } ;
13
16
14
17
export type Destination = Writable & MightBeFlushable ;
15
18
@@ -21,13 +24,20 @@ export function flushBuffered(destination: Destination) {
21
24
// If we don't have any more data to send right now.
22
25
// Flush whatever is in the buffer to the wire.
23
26
if ( typeof destination . flush === 'function' ) {
24
- // By convention the Zlib streams provide a flush function for this purpose.
25
- destination . flush ( ) ;
27
+ // http.createServer response have flush(), but it has a different meaning and
28
+ // is deprecated in favor of flushHeaders(). Detect to avoid a warning.
29
+ if ( typeof destination . flushHeaders !== 'function' ) {
30
+ // By convention the Zlib streams provide a flush function for this purpose.
31
+ destination . flush ( ) ;
32
+ }
26
33
}
27
34
}
28
35
29
36
export function beginWriting ( destination : Destination ) {
30
- destination . cork ( ) ;
37
+ // Older Node streams like http.createServer don't have this.
38
+ if ( typeof destination . cork === 'function' ) {
39
+ destination . cork ( ) ;
40
+ }
31
41
}
32
42
33
43
export function writeChunk ( destination : Destination , buffer : Uint8Array ) {
@@ -36,7 +46,10 @@ export function writeChunk(destination: Destination, buffer: Uint8Array) {
36
46
}
37
47
38
48
export function completeWriting ( destination : Destination ) {
39
- destination . uncork ( ) ;
49
+ // Older Node streams like http.createServer don't have this.
50
+ if ( typeof destination . uncork === 'function' ) {
51
+ destination . uncork ( ) ;
52
+ }
40
53
}
41
54
42
55
export function close ( destination : Destination ) {
0 commit comments