ソースを参照

append to index file whenever possible

Gil Pedersen 11 年 前
コミット
3f5386c376
1 ファイル変更13 行追加2 行削除
  1. 13 2
      lib/recorder.js

+ 13 - 2
lib/recorder.js

@@ -200,8 +200,19 @@ HlsStreamRecorder.prototype.segmentName = function(seqNo) {
 };
 
 HlsStreamRecorder.prototype.flushIndex = function(cb) {
-  // TODO: make atomic by writing to temp file & renaming
-  fs.writeFile(path.join(this.dst, 'index.m3u8'), this.index, cb);
+  var appendString, indexString = this.index.toString().trim();
+  if (this.lastIndexString && indexString.lastIndexOf(this.lastIndexString, 0) === 0) {
+    var lastLength = this.lastIndexString.length;
+    appendString = indexString.substr(lastLength);
+  }
+  this.lastIndexString = indexString;
+
+  if (appendString) {
+    fs.appendFile(path.join(this.dst, 'index.m3u8'), appendString, cb);
+  } else {
+    fs.writeFile(path.join(this.dst, 'index.m3u8'), indexString, cb);
+  }
+};
 
 HlsStreamRecorder.prototype.recorderForUrl = function(remoteUrl) {
   var idx, len = this.recorders.length;