File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,7 @@ WriteRequest.prototype.makeWriter = function () {
131
131
self . writer = writer
132
132
133
133
writer . onwriteend = function ( e ) {
134
- self . file . updateSize ( e . currentTarget . length )
135
- self . onwrite ( null )
134
+ self . onwrite ( null , e )
136
135
}
137
136
138
137
writer . onerror = function ( err ) {
@@ -143,7 +142,7 @@ WriteRequest.prototype.makeWriter = function () {
143
142
} )
144
143
}
145
144
146
- WriteRequest . prototype . onwrite = function ( err ) {
145
+ WriteRequest . prototype . onwrite = function ( err , e ) {
147
146
const req = this . req
148
147
this . req = null
149
148
@@ -152,6 +151,10 @@ WriteRequest.prototype.onwrite = function (err) {
152
151
this . mutex . release ( )
153
152
}
154
153
154
+ if ( ! err ) {
155
+ this . file . updateSize ( e . currentTarget . length , this . truncating )
156
+ }
157
+
155
158
if ( this . truncating ) {
156
159
this . truncating = false
157
160
if ( ! err ) return this . run ( req )
@@ -244,7 +247,16 @@ ReadRequest.prototype.onread = function (err, buf) {
244
247
245
248
if ( err && this . retry ) {
246
249
this . retry = false
247
- if ( this . lock ( this ) ) this . run ( req )
250
+ if ( this . lock ( this ) ) {
251
+ this . file . clearFile ( )
252
+ this . run ( req )
253
+ }
254
+ return
255
+ }
256
+
257
+ if ( err && err . name === 'NotReadableError' ) {
258
+ this . file . clearFile ( )
259
+ this . run ( req )
248
260
return
249
261
}
250
262
@@ -287,8 +299,15 @@ class EntryFile {
287
299
return this . _size
288
300
}
289
301
290
- updateSize ( size ) {
291
- this . _size = size
302
+ updateSize ( size , truncating = false ) {
303
+ if ( truncating || size > this . _size ) {
304
+ this . _size = size
305
+ }
306
+
307
+ this . clearFile ( )
308
+ }
309
+
310
+ clearFile ( ) {
292
311
this . _file = null
293
312
}
294
313
Original file line number Diff line number Diff line change 10
10
"devDependencies" : {
11
11
"budo" : " ^11.6.3" ,
12
12
"puppeteer" : " ^3.0.2" ,
13
- "random-access-test" : " github:random-access-storage/random-access-test " ,
13
+ "random-access-test" : " ^1.0.0 " ,
14
14
"standard" : " ^11.0.1" ,
15
15
"tap-finished" : " 0.0.1" ,
16
16
"tape" : " ^5.0.0"
You can’t perform that action at this time.
0 commit comments