@@ -34,18 +34,21 @@ class Header {
3434 this . atime = null
3535 this . ctime = null
3636
37- if ( Buffer . isBuffer ( data ) )
37+ if ( Buffer . isBuffer ( data ) ) {
3838 this . decode ( data , off || 0 , ex , gex )
39- else if ( data )
39+ } else if ( data ) {
4040 this . set ( data )
41+ }
4142 }
4243
4344 decode ( buf , off , ex , gex ) {
44- if ( ! off )
45+ if ( ! off ) {
4546 off = 0
47+ }
4648
47- if ( ! buf || ! ( buf . length >= off + 512 ) )
49+ if ( ! buf || ! ( buf . length >= off + 512 ) ) {
4850 throw new Error ( 'need 512 bytes for header' )
51+ }
4952
5053 this . path = decString ( buf , off , 100 )
5154 this . mode = decNumber ( buf , off + 100 , 8 )
@@ -62,18 +65,21 @@ class Header {
6265
6366 // old tar versions marked dirs as a file with a trailing /
6467 this [ TYPE ] = decString ( buf , off + 156 , 1 )
65- if ( this [ TYPE ] === '' )
68+ if ( this [ TYPE ] === '' ) {
6669 this [ TYPE ] = '0'
67- if ( this [ TYPE ] === '0' && this . path . substr ( - 1 ) === '/' )
70+ }
71+ if ( this [ TYPE ] === '0' && this . path . slice ( - 1 ) === '/' ) {
6872 this [ TYPE ] = '5'
73+ }
6974
7075 // tar implementations sometimes incorrectly put the stat(dir).size
7176 // as the size in the tarball, even though Directory entries are
7277 // not able to have any body at all. In the very rare chance that
7378 // it actually DOES have a body, we weren't going to do anything with
7479 // it anyway, and it'll just be a warning about an invalid header.
75- if ( this [ TYPE ] === '5' )
80+ if ( this [ TYPE ] === '5' ) {
7681 this . size = 0
82+ }
7783
7884 this . linkpath = decString ( buf , off + 157 , 100 )
7985 if ( buf . slice ( off + 257 , off + 265 ) . toString ( ) === 'ustar\u000000' ) {
@@ -87,32 +93,37 @@ class Header {
8793 this . path = prefix + '/' + this . path
8894 } else {
8995 const prefix = decString ( buf , off + 345 , 130 )
90- if ( prefix )
96+ if ( prefix ) {
9197 this . path = prefix + '/' + this . path
98+ }
9299 this . atime = decDate ( buf , off + 476 , 12 )
93100 this . ctime = decDate ( buf , off + 488 , 12 )
94101 }
95102 }
96103
97104 let sum = 8 * 0x20
98- for ( let i = off ; i < off + 148 ; i ++ )
105+ for ( let i = off ; i < off + 148 ; i ++ ) {
99106 sum += buf [ i ]
107+ }
100108
101- for ( let i = off + 156 ; i < off + 512 ; i ++ )
109+ for ( let i = off + 156 ; i < off + 512 ; i ++ ) {
102110 sum += buf [ i ]
111+ }
103112
104113 this . cksumValid = sum === this . cksum
105- if ( this . cksum === null && sum === 8 * 0x20 )
114+ if ( this . cksum === null && sum === 8 * 0x20 ) {
106115 this . nullBlock = true
116+ }
107117 }
108118
109119 [ SLURP ] ( ex , global ) {
110120 for ( const k in ex ) {
111121 // we slurp in everything except for the path attribute in
112122 // a global extended header, because that's weird.
113123 if ( ex [ k ] !== null && ex [ k ] !== undefined &&
114- ! ( global && k === 'path' ) )
124+ ! ( global && k === 'path' ) ) {
115125 this [ k ] = ex [ k ]
126+ }
116127 }
117128 }
118129
@@ -122,11 +133,13 @@ class Header {
122133 off = 0
123134 }
124135
125- if ( ! off )
136+ if ( ! off ) {
126137 off = 0
138+ }
127139
128- if ( ! ( buf . length >= off + 512 ) )
140+ if ( ! ( buf . length >= off + 512 ) ) {
129141 throw new Error ( 'need 512 bytes for header' )
142+ }
130143
131144 const prefixSize = this . ctime || this . atime ? 130 : 155
132145 const split = splitPrefix ( this . path || '' , prefixSize )
@@ -148,20 +161,22 @@ class Header {
148161 this . needPax = encNumber ( buf , off + 329 , 8 , this . devmaj ) || this . needPax
149162 this . needPax = encNumber ( buf , off + 337 , 8 , this . devmin ) || this . needPax
150163 this . needPax = encString ( buf , off + 345 , prefixSize , prefix ) || this . needPax
151- if ( buf [ off + 475 ] !== 0 )
164+ if ( buf [ off + 475 ] !== 0 ) {
152165 this . needPax = encString ( buf , off + 345 , 155 , prefix ) || this . needPax
153- else {
166+ } else {
154167 this . needPax = encString ( buf , off + 345 , 130 , prefix ) || this . needPax
155168 this . needPax = encDate ( buf , off + 476 , 12 , this . atime ) || this . needPax
156169 this . needPax = encDate ( buf , off + 488 , 12 , this . ctime ) || this . needPax
157170 }
158171
159172 let sum = 8 * 0x20
160- for ( let i = off ; i < off + 148 ; i ++ )
173+ for ( let i = off ; i < off + 148 ; i ++ ) {
161174 sum += buf [ i ]
175+ }
162176
163- for ( let i = off + 156 ; i < off + 512 ; i ++ )
177+ for ( let i = off + 156 ; i < off + 512 ; i ++ ) {
164178 sum += buf [ i ]
179+ }
165180
166181 this . cksum = sum
167182 encNumber ( buf , off + 148 , 8 , this . cksum )
@@ -172,8 +187,9 @@ class Header {
172187
173188 set ( data ) {
174189 for ( const i in data ) {
175- if ( data [ i ] !== null && data [ i ] !== undefined )
190+ if ( data [ i ] !== null && data [ i ] !== undefined ) {
176191 this [ i ] = data [ i ]
192+ }
177193 }
178194 }
179195
@@ -186,10 +202,11 @@ class Header {
186202 }
187203
188204 set type ( type ) {
189- if ( types . code . has ( type ) )
205+ if ( types . code . has ( type ) ) {
190206 this [ TYPE ] = types . code . get ( type )
191- else
207+ } else {
192208 this [ TYPE ] = type
209+ }
193210 }
194211}
195212
@@ -200,34 +217,33 @@ const splitPrefix = (p, prefixSize) => {
200217 let ret
201218 const root = pathModule . parse ( p ) . root || '.'
202219
203- if ( Buffer . byteLength ( pp ) < pathSize )
220+ if ( Buffer . byteLength ( pp ) < pathSize ) {
204221 ret = [ pp , prefix , false ]
205- else {
222+ } else {
206223 // first set prefix to the dir, and path to the base
207224 prefix = pathModule . dirname ( pp )
208225 pp = pathModule . basename ( pp )
209226
210227 do {
211- // both fit!
212228 if ( Buffer . byteLength ( pp ) <= pathSize &&
213- Buffer . byteLength ( prefix ) <= prefixSize )
229+ Buffer . byteLength ( prefix ) <= prefixSize ) {
230+ // both fit!
214231 ret = [ pp , prefix , false ]
215-
216- // prefix fits in prefix, but path doesn't fit in path
217- else if ( Buffer . byteLength ( pp ) > pathSize &&
218- Buffer . byteLength ( prefix ) <= prefixSize )
219- ret = [ pp . substr ( 0 , pathSize - 1 ) , prefix , true ]
220-
221- else {
232+ } else if ( Buffer . byteLength ( pp ) > pathSize &&
233+ Buffer . byteLength ( prefix ) <= prefixSize ) {
234+ // prefix fits in prefix, but path doesn't fit in path
235+ ret = [ pp . slice ( 0 , pathSize - 1 ) , prefix , true ]
236+ } else {
222237 // make path take a bit from prefix
223238 pp = pathModule . join ( pathModule . basename ( prefix ) , pp )
224239 prefix = pathModule . dirname ( prefix )
225240 }
226241 } while ( prefix !== root && ! ret )
227242
228243 // at this point, found no resolution, just truncate
229- if ( ! ret )
230- ret = [ p . substr ( 0 , pathSize - 1 ) , '' , true ]
244+ if ( ! ret ) {
245+ ret = [ p . slice ( 0 , pathSize - 1 ) , '' , true ]
246+ }
231247 }
232248 return ret
233249}
0 commit comments