Commit 096dc4d 1 parent 9d71c56 commit 096dc4d Copy full SHA for 096dc4d
File tree 4 files changed +38
-5
lines changed
4 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ const maxMetaEntrySize = 1024 * 1024
28
28
const Entry = require ( './read-entry.js' )
29
29
const Pax = require ( './pax.js' )
30
30
const zlib = require ( 'minizlib' )
31
+ const { nextTick } = require ( 'process' )
31
32
32
33
const gzipHeader = Buffer . from ( [ 0x1f , 0x8b ] )
33
34
const STATE = Symbol ( 'state' )
@@ -59,6 +60,7 @@ const DONE = Symbol('onDone')
59
60
const SAW_VALID_ENTRY = Symbol ( 'sawValidEntry' )
60
61
const SAW_NULL_BLOCK = Symbol ( 'sawNullBlock' )
61
62
const SAW_EOF = Symbol ( 'sawEOF' )
63
+ const CLOSESTREAM = Symbol ( 'closeStream' )
62
64
63
65
const noop = _ => true
64
66
@@ -89,7 +91,6 @@ module.exports = warner(class Parser extends EE {
89
91
this . emit ( 'prefinish' )
90
92
this . emit ( 'finish' )
91
93
this . emit ( 'end' )
92
- this . emit ( 'close' )
93
94
} )
94
95
}
95
96
@@ -114,6 +115,9 @@ module.exports = warner(class Parser extends EE {
114
115
this [ ABORTED ] = false
115
116
this [ SAW_NULL_BLOCK ] = false
116
117
this [ SAW_EOF ] = false
118
+
119
+ this . on ( 'end' , ( ) => this [ CLOSESTREAM ] ( ) )
120
+
117
121
if ( typeof opt . onwarn === 'function' ) {
118
122
this . on ( 'warn' , opt . onwarn )
119
123
}
@@ -217,6 +221,10 @@ module.exports = warner(class Parser extends EE {
217
221
}
218
222
}
219
223
224
+ [ CLOSESTREAM ] ( ) {
225
+ nextTick ( ( ) => this . emit ( 'close' ) )
226
+ }
227
+
220
228
[ PROCESSENTRY ] ( entry ) {
221
229
let go = true
222
230
Original file line number Diff line number Diff line change @@ -234,7 +234,6 @@ class Unpack extends Parser {
234
234
this . emit ( 'prefinish' )
235
235
this . emit ( 'finish' )
236
236
this . emit ( 'end' )
237
- this . emit ( 'close' )
238
237
}
239
238
}
240
239
Original file line number Diff line number Diff line change 33
33
"events-to-array" : " ^1.1.2" ,
34
34
"mutate-fs" : " ^2.1.1" ,
35
35
"rimraf" : " ^3.0.2" ,
36
- "tap" : " ^16.0.1" ,
37
- "tar-fs" : " ^2.1.1" ,
38
- "tar-stream" : " ^2.2.0"
36
+ "tap" : " ^16.0.1"
39
37
},
40
38
"license" : " ISC" ,
41
39
"engines" : {
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ const mkdirp = require('mkdirp')
10
10
const { promisify } = require ( 'util' )
11
11
const rimraf = promisify ( require ( 'rimraf' ) )
12
12
const mutateFS = require ( 'mutate-fs' )
13
+ const pipeline = promisify ( require ( 'stream' ) . pipeline )
14
+ const https = require ( 'https' )
13
15
14
16
t . teardown ( _ => rimraf ( extractdir ) )
15
17
@@ -54,6 +56,32 @@ t.test('basic extracting', t => {
54
56
t . end ( )
55
57
} )
56
58
59
+ t . test ( 'ensure an open stream is not prematuraly closed' , t => {
60
+ const dir = path . resolve ( extractdir , 'basic-with-stream' )
61
+
62
+ t . beforeEach ( async ( ) => {
63
+ await rimraf ( dir )
64
+ await mkdirp ( dir )
65
+ } )
66
+
67
+ const check = async t => {
68
+ fs . lstatSync ( dir + '/node-tar-main/LICENSE' )
69
+ await rimraf ( dir )
70
+ t . end ( )
71
+ }
72
+
73
+ t . test ( 'async promisey' , t => {
74
+ https . get ( 'https://codeload.github.com/npm/node-tar/tar.gz/main' , ( stream ) => {
75
+ return pipeline (
76
+ stream ,
77
+ x ( { cwd : dir } , [ 'node-tar-main/LICENSE' ] )
78
+ ) . then ( _ => check ( t ) )
79
+ } )
80
+ } )
81
+
82
+ t . end ( )
83
+ } )
84
+
57
85
t . test ( 'file list and filter' , t => {
58
86
const file = path . resolve ( tars , 'utf8.tar' )
59
87
const dir = path . resolve ( extractdir , 'filter' )
You can’t perform that action at this time.
0 commit comments