@@ -144,8 +144,8 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
144
144
ctime : this . portable ? null : this . stat . ctime
145
145
} )
146
146
147
- if ( this . header . encode ( ) && ! this . noPax )
148
- this . write ( new Pax ( {
147
+ if ( this . header . encode ( ) && ! this . noPax ) {
148
+ super . write ( new Pax ( {
149
149
atime : this . portable ? null : this . header . atime ,
150
150
ctime : this . portable ? null : this . header . ctime ,
151
151
gid : this . portable ? null : this . header . gid ,
@@ -159,7 +159,8 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
159
159
ino : this . portable ? null : this . stat . ino ,
160
160
nlink : this . portable ? null : this . stat . nlink
161
161
} ) . encode ( ) )
162
- this . write ( this . header . block )
162
+ }
163
+ super . write ( this . header . block )
163
164
}
164
165
165
166
[ DIRECTORY ] ( ) {
@@ -280,10 +281,6 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
280
281
281
282
const writeBuf = this . offset === 0 && bytesRead === this . buf . length ?
282
283
this . buf : this . buf . slice ( this . offset , this . offset + bytesRead )
283
- this . remain -= writeBuf . length
284
- this . blockRemain -= writeBuf . length
285
- this . pos += writeBuf . length
286
- this . offset += writeBuf . length
287
284
288
285
const flushed = this . write ( writeBuf )
289
286
if ( ! flushed )
@@ -296,10 +293,23 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
296
293
this . once ( 'drain' , cb )
297
294
}
298
295
296
+ write ( writeBuf ) {
297
+ if ( this . blockRemain < writeBuf . length ) {
298
+ const er = new Error ( 'writing more data than expected' )
299
+ er . path = this . absolute
300
+ return this . emit ( 'error' , er )
301
+ }
302
+ this . remain -= writeBuf . length
303
+ this . blockRemain -= writeBuf . length
304
+ this . pos += writeBuf . length
305
+ this . offset += writeBuf . length
306
+ return super . write ( writeBuf )
307
+ }
308
+
299
309
[ ONDRAIN ] ( ) {
300
310
if ( ! this . remain ) {
301
311
if ( this . blockRemain )
302
- this . write ( Buffer . alloc ( this . blockRemain ) )
312
+ super . write ( Buffer . alloc ( this . blockRemain ) )
303
313
return this [ CLOSE ] ( /* istanbul ignore next - legacy */
304
314
er => er ? this . emit ( 'error' , er ) : this . end ( ) )
305
315
}
@@ -454,7 +464,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
454
464
455
465
end ( ) {
456
466
if ( this . blockRemain )
457
- this . write ( Buffer . alloc ( this . blockRemain ) )
467
+ super . write ( Buffer . alloc ( this . blockRemain ) )
458
468
return super . end ( )
459
469
}
460
470
} )
0 commit comments