@@ -84,41 +84,41 @@ class Parser {
8484 protected state : ParserState = ParserState . HEADER ;
8585 protected remainingBytes = 0 ;
8686
87- protected parseHeader ( array : Uint8Array ) : TokenHeader {
87+ protected parseHeader ( header : Uint8Array ) : TokenHeader {
8888 // 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 ) ;
9191
9292 if ( headerChecksum !== calculatedChecksum ) {
9393 throw new errors . ErrorVirtualTarParserInvalidHeader (
9494 `Expected checksum to be ${ calculatedChecksum } but received ${ headerChecksum } ` ,
9595 ) ;
9696 }
9797
98- const ustarMagic = utils . decodeUstarMagic ( array ) ;
98+ const ustarMagic = utils . decodeUstarMagic ( header ) ;
9999 if ( ustarMagic !== constants . USTAR_NAME ) {
100100 throw new errors . ErrorVirtualTarParserInvalidHeader (
101101 `Expected ustar magic to be '${ constants . USTAR_NAME } ', got '${ ustarMagic } '` ,
102102 ) ;
103103 }
104104
105- const ustarVersion = utils . decodeUstarVersion ( array ) ;
105+ const ustarVersion = utils . decodeUstarVersion ( header ) ;
106106 if ( ustarVersion !== constants . USTAR_VERSION ) {
107107 throw new errors . ErrorVirtualTarParserInvalidHeader (
108108 `Expected ustar version to be '${ constants . USTAR_VERSION } ', got '${ ustarVersion } '` ,
109109 ) ;
110110 }
111111
112112 // 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 ) ;
122122
123123 return {
124124 type : 'header' ,
@@ -212,6 +212,12 @@ class Parser {
212212 this . state = ParserState . DATA ;
213213 this . remainingBytes = headerToken . fileSize ;
214214 }
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+
215221 return headerToken ;
216222 }
217223
@@ -225,7 +231,7 @@ class Parser {
225231 case ParserState . NULL : {
226232 if ( utils . isNullBlock ( data ) ) {
227233 this . state = ParserState . ENDED ;
228- return { type : 'end' } as TokenEnd ;
234+ return { type : 'end' } ;
229235 } else {
230236 throw new errors . ErrorVirtualTarParserEndOfArchive (
231237 'Received garbage data after first end marker' ,
@@ -234,7 +240,7 @@ class Parser {
234240 }
235241
236242 default :
237- utils . never ( ' Unexpected state' ) ;
243+ utils . never ( ` Unexpected state: ${ this . state } ` ) ;
238244 }
239245 }
240246}
0 commit comments