@@ -45,55 +45,51 @@ const ignore = async (stream) => {
45
45
}
46
46
47
47
async function * parseEntry ( stream , options ) {
48
- let entry = { }
49
-
50
48
for await ( const part of stream ) {
51
- let type
49
+ if ( ! part . headers [ 'content-type' ] ) {
50
+ throw new Error ( 'No content-type in multipart part' )
51
+ }
52
52
53
- if ( part . headers [ 'content-type' ] ) {
54
- type = Content . type ( part . headers [ 'content-type' ] )
53
+ const type = Content . type ( part . headers [ 'content-type' ] )
55
54
56
- if ( type . boundary ) {
57
- // recursively parse nested multiparts
58
- yield * parser ( part . body , {
59
- ...options ,
60
- boundary : type . boundary
61
- } )
55
+ if ( type . boundary ) {
56
+ // recursively parse nested multiparts
57
+ yield * parser ( part . body , {
58
+ ...options ,
59
+ boundary : type . boundary
60
+ } )
62
61
63
- continue
64
- }
62
+ continue
65
63
}
66
64
67
65
if ( ! part . headers [ 'content-disposition' ] ) {
68
66
throw new Error ( 'No content disposition in multipart part' )
69
67
}
70
68
71
- const disposition = parseDisposition ( part . headers [ 'content-disposition' ] )
69
+ const entry = { }
72
70
73
- if ( disposition . name . includes ( ' mtime' ) ) {
74
- entry . mtime = parseInt ( ( await collect ( part . body ) ) . toString ( 'utf8' ) , 10 )
71
+ if ( part . headers . mtime ) {
72
+ entry . mtime = parseInt ( part . headers . mtime , 10 )
75
73
}
76
74
77
- if ( disposition . name . includes ( ' mode' ) ) {
78
- entry . mode = parseInt ( ( await collect ( part . body ) ) . toString ( 'utf8' ) , 10 )
75
+ if ( part . headers . mode ) {
76
+ entry . mode = parseInt ( part . headers . mode , 8 )
79
77
}
80
78
81
- if ( type ) {
82
- if ( isDirectory ( type . mime ) ) {
83
- entry . type = 'directory'
84
- } else if ( type . mime === applicationSymlink ) {
85
- entry . type = 'symlink'
86
- } else {
87
- entry . type = 'file'
88
- }
79
+ if ( isDirectory ( type . mime ) ) {
80
+ entry . type = 'directory'
81
+ } else if ( type . mime === applicationSymlink ) {
82
+ entry . type = 'symlink'
83
+ } else {
84
+ entry . type = 'file'
85
+ }
89
86
90
- entry . name = decodeURIComponent ( disposition . filename )
91
- entry . body = part . body
87
+ const disposition = parseDisposition ( part . headers [ 'content-disposition' ] )
92
88
93
- yield entry
89
+ entry . name = decodeURIComponent ( disposition . filename )
90
+ entry . body = part . body
94
91
95
- entry = { }
96
- }
92
+ yield entry
97
93
}
98
94
}
99
95
0 commit comments