@@ -84,41 +84,41 @@ class Parser {
84
84
protected state : ParserState = ParserState . HEADER ;
85
85
protected remainingBytes = 0 ;
86
86
87
- protected parseHeader ( array : Uint8Array ) : TokenHeader {
87
+ protected parseHeader ( header : Uint8Array ) : TokenHeader {
88
88
// Validate header by checking checksum and magic string
89
- const headerChecksum = utils . decodeChecksum ( array ) ;
90
- const calculatedChecksum = utils . calculateChecksum ( array ) ;
89
+ const headerChecksum = utils . decodeChecksum ( header ) ;
90
+ const calculatedChecksum = utils . calculateChecksum ( header ) ;
91
91
92
92
if ( headerChecksum !== calculatedChecksum ) {
93
93
throw new errors . ErrorVirtualTarParserInvalidHeader (
94
94
`Expected checksum to be ${ calculatedChecksum } but received ${ headerChecksum } ` ,
95
95
) ;
96
96
}
97
97
98
- const ustarMagic = utils . decodeUstarMagic ( array ) ;
98
+ const ustarMagic = utils . decodeUstarMagic ( header ) ;
99
99
if ( ustarMagic !== constants . USTAR_NAME ) {
100
100
throw new errors . ErrorVirtualTarParserInvalidHeader (
101
101
`Expected ustar magic to be '${ constants . USTAR_NAME } ', got '${ ustarMagic } '` ,
102
102
) ;
103
103
}
104
104
105
- const ustarVersion = utils . decodeUstarVersion ( array ) ;
105
+ const ustarVersion = utils . decodeUstarVersion ( header ) ;
106
106
if ( ustarVersion !== constants . USTAR_VERSION ) {
107
107
throw new errors . ErrorVirtualTarParserInvalidHeader (
108
108
`Expected ustar version to be '${ constants . USTAR_VERSION } ', got '${ ustarVersion } '` ,
109
109
) ;
110
110
}
111
111
112
112
// Extract the relevant metadata from the header
113
- const filePath = utils . decodeFilePath ( array ) ;
114
- const fileSize = utils . decodeFileSize ( array ) ;
115
- const fileMtime = utils . decodeFileMtime ( array ) ;
116
- const fileMode = utils . decodeFileMode ( array ) ;
117
- const ownerUid = utils . decodeOwnerUid ( array ) ;
118
- const ownerGid = utils . decodeOwnerGid ( array ) ;
119
- const ownerUserName = utils . decodeOwnerUserName ( array ) ;
120
- const ownerGroupName = utils . decodeOwnerGroupName ( array ) ;
121
- const fileType = utils . decodeFileType ( array ) ;
113
+ const filePath = utils . decodeFilePath ( header ) ;
114
+ const fileMode = utils . decodeFileMode ( header ) ;
115
+ const ownerUid = utils . decodeOwnerUid ( header ) ;
116
+ const ownerGid = utils . decodeOwnerGid ( header ) ;
117
+ const fileSize = utils . decodeFileSize ( header ) ;
118
+ const fileMtime = utils . decodeFileMtime ( header ) ;
119
+ const fileType = utils . decodeFileType ( header ) ;
120
+ const ownerUserName = utils . decodeOwnerUserName ( header ) ;
121
+ const ownerGroupName = utils . decodeOwnerGroupName ( header ) ;
122
122
123
123
return {
124
124
type : 'header' ,
@@ -212,6 +212,12 @@ class Parser {
212
212
this . state = ParserState . DATA ;
213
213
this . remainingBytes = headerToken . fileSize ;
214
214
}
215
+
216
+ // Only the file header and the extended header can potentially have
217
+ // additional data blocks following them. This needs to be tracked in
218
+ // the parser state. Directory headers don't have this issue and doesn't
219
+ // need any additional processing.
220
+
215
221
return headerToken ;
216
222
}
217
223
@@ -225,7 +231,7 @@ class Parser {
225
231
case ParserState . NULL : {
226
232
if ( utils . isNullBlock ( data ) ) {
227
233
this . state = ParserState . ENDED ;
228
- return { type : 'end' } as TokenEnd ;
234
+ return { type : 'end' } ;
229
235
} else {
230
236
throw new errors . ErrorVirtualTarParserEndOfArchive (
231
237
'Received garbage data after first end marker' ,
@@ -234,7 +240,7 @@ class Parser {
234
240
}
235
241
236
242
default :
237
- utils . never ( ' Unexpected state' ) ;
243
+ utils . never ( ` Unexpected state: ${ this . state } ` ) ;
238
244
}
239
245
}
240
246
}
0 commit comments