Skip to content

Commit 069dfa1

Browse files
committed
Fix hanging when uploading 0 byte file
1 parent ade47b5 commit 069dfa1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

qiniu/storage/resume.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ function putReq(config, uploadToken, key, rsStream, rsStreamLen, putExtra,
144144
}
145145

146146
var isEnd = rsStream._readableState.ended;
147-
147+
var isSent = false;
148+
148149
//check when to mkblk
149150
rsStream.on('data', function(chunk) {
150151
readLen += chunk.length;
@@ -182,22 +183,21 @@ function putReq(config, uploadToken, key, rsStream, rsStreamLen, putExtra,
182183

183184
rsStream.resume();
184185
if (isEnd || finishedCtxList.length === Math.floor(totalBlockNum)) {
185-
mkfileReq(upDomain, uploadToken, fileSize, finishedCtxList, key, putExtra, callbackFunc);
186+
mkfileReq(upDomain, uploadToken, fileSize, finishedCtxList, key, putExtra, callbackFunc);
187+
isSent = true;
186188
}
187189
}
188190
});
189191
}
190192
}
191193
});
192194

193-
//check when to mkfile
194-
// rsStream.on('end', function() {
195-
// //console.log("end");
196-
// if (!isEnd) {
197-
// console.log("end");
198-
// mkfileReq(upDomain, uploadToken, fileSize, finishedCtxList, key,
199-
// putExtra, callbackFunc)}
200-
// });
195+
rsStream.on('end', function () {
196+
// 0B file won't trigger 'data' event
197+
if (!isSent && rsStreamLen === 0) {
198+
mkfileReq(upDomain, uploadToken, fileSize, finishedCtxList, key, putExtra, callbackFunc)
199+
}
200+
})
201201
}
202202

203203
function mkblkReq(upDomain, uploadToken, blkData, callbackFunc) {

0 commit comments

Comments
 (0)