@@ -150,7 +150,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
150150 } )
151151
152152 if ( this . header . encode ( ) && ! this . noPax ) {
153- this . write ( new Pax ( {
153+ super . write ( new Pax ( {
154154 atime : this . portable ? null : this . header . atime ,
155155 ctime : this . portable ? null : this . header . ctime ,
156156 gid : this . portable ? null : this . header . gid ,
@@ -165,7 +165,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
165165 nlink : this . portable ? null : this . stat . nlink ,
166166 } ) . encode ( ) )
167167 }
168- this . write ( this . header . block )
168+ super . write ( this . header . block )
169169 }
170170
171171 [ DIRECTORY ] ( ) {
@@ -286,10 +286,6 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
286286
287287 const writeBuf = this . offset === 0 && bytesRead === this . buf . length ?
288288 this . buf : this . buf . slice ( this . offset , this . offset + bytesRead )
289- this . remain -= writeBuf . length
290- this . blockRemain -= writeBuf . length
291- this . pos += writeBuf . length
292- this . offset += writeBuf . length
293289
294290 const flushed = this . write ( writeBuf )
295291 if ( ! flushed )
@@ -302,10 +298,23 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
302298 this . once ( 'drain' , cb )
303299 }
304300
301+ write ( writeBuf ) {
302+ if ( this . blockRemain < writeBuf . length ) {
303+ const er = new Error ( 'writing more data than expected' )
304+ er . path = this . absolute
305+ return this . emit ( 'error' , er )
306+ }
307+ this . remain -= writeBuf . length
308+ this . blockRemain -= writeBuf . length
309+ this . pos += writeBuf . length
310+ this . offset += writeBuf . length
311+ return super . write ( writeBuf )
312+ }
313+
305314 [ ONDRAIN ] ( ) {
306315 if ( ! this . remain ) {
307316 if ( this . blockRemain )
308- this . write ( Buffer . alloc ( this . blockRemain ) )
317+ super . write ( Buffer . alloc ( this . blockRemain ) )
309318 return this [ CLOSE ] ( er => er ? this . emit ( 'error' , er ) : this . end ( ) )
310319 }
311320
@@ -461,7 +470,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
461470
462471 end ( ) {
463472 if ( this . blockRemain )
464- this . write ( Buffer . alloc ( this . blockRemain ) )
473+ super . write ( Buffer . alloc ( this . blockRemain ) )
465474 return super . end ( )
466475 }
467476} )
0 commit comments