var metafilename = unify.fullPathDirName + "/.meta."+ path.basename(unify.requestFor) +".filesize";
var fsizef = fs.createReadStream(metafilename);
var fsize = "";
+ var lastchunk = 0;
fsizef.on("data", function(data) {
fsize += data;
});
fs.stat(unify.fullFilePath, function(err, stats) {
if(err == null) {
if(stats["size"] > sentSoFar) {
+ // if file size changed between last chunk and this chunk, send the chunks
+
+ lastChunk = 0;
// open the file, send the data
var rs = fs.createReadStream(unify.fullFilePath, {start: sentSoFar, end: stats["size"]});
unify.b.end();
}
});
+ } else {
+ // if file size did not change between last timeout and this one, incremement the chunk counter
+ // if we reach 60, we had a problem, and so we bomb out
+
+ lastChunk++;
+
+ // we bombed out somehow
+ if(lastChunk > 60) {
+ unify.b.end();
+ } else {
+ setTimeout(sendPieces, 1000);
+ }
}
} else {
console.log("inline service - we're in a very bad place");