Gil Pedersen 12 anni fa
parent
commit
303ec1c3f6
1 ha cambiato i file con 4 aggiunte e 6 eliminazioni
  1. 4 6
      lib/reader.js

+ 4 - 6
lib/reader.js

@@ -80,10 +80,11 @@ function fetchfrom(reader, seqNo, segment, cb) {
   stream.on('end', onfail);
   stream.on('error', onfail);
 
-  function cleanup() {
+  function finish(err, res) {
     stream.removeListener('meta', onmeta);
     stream.removeListener('end', onfail);
     stream.removeListener('error', onfail);
+    cb(err, res);
   }
 
   function onmeta(meta) {
@@ -96,15 +97,12 @@ function fetchfrom(reader, seqNo, segment, cb) {
       return stream.emit(new Error('Unsupported segment MIME type: '+meta.mime));
     }
 
-    cleanup();
-    cb(null, new HlsSegmentObject(seqNo, segment, meta, stream));
+    finish(null, new HlsSegmentObject(seqNo, segment, meta, stream));
   }
 
   function onfail(err) {
     if (!err) err = new Error('No metadata');
-
-    cleanup();
-    cb(err)
+    finish(err);
   }
 
   return stream;