Jelajahi Sumber

make index updates atomic

Gil Pedersen 11 tahun lalu
induk
melakukan
f58a8a9f00
2 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 2 1
      lib/recorder.js
  2. 1 0
      package.json

+ 2 - 1
lib/recorder.js

@@ -12,6 +12,7 @@ var mime = require('mime-types'),
     oncemore = require('oncemore'),
     m3u8parse = require('m3u8parse'),
     mkdirp = require('mkdirp'),
+    writeFileAtomic = require('write-file-atomic'),
     debug = require('debug')('hls:recorder');
 
 // add custom extensions
@@ -216,7 +217,7 @@ HlsStreamRecorder.prototype.flushIndex = function(cb) {
   if (appendString) {
     fs.appendFile(path.join(this.dst, 'index.m3u8'), appendString, cb);
   } else {
-    fs.writeFile(path.join(this.dst, 'index.m3u8'), indexString, cb);
+    writeFileAtomic(path.join(this.dst, 'index.m3u8'), indexString, cb);
   }
 };
 

+ 1 - 0
package.json

@@ -40,6 +40,7 @@
     "streamprocess": "0.0.1",
     "udp-blast": "^1.0.0",
     "uristream": "^1.1.0",
+    "write-file-atomic": "^1.1.0",
     "xtend": "^4.0.0"
   },
   "devDependencies": {