فهرست منبع

Pass the `start` and `end` options down to `fs.createReadStream`, and test for same.

Shane Kilkelly 11 سال پیش
والد
کامیت
d88736e3b5

+ 1 - 1
services/filestore/app/coffee/FSPersistorManager.coffee

@@ -33,7 +33,7 @@ module.exports =
       _callback = () ->
     filteredName = filterName name
     logger.log location:location, name:filteredName, "getting file"
-    sourceStream = fs.createReadStream "#{location}/#{filteredName}"
+    sourceStream = fs.createReadStream "#{location}/#{filteredName}", opts
     sourceStream.on 'error', (err) ->
       logger.err err:err, location:location, name:name, "Error reading from file"
       if err.code = 'ENOENT'

+ 17 - 4
services/filestore/test/unit/coffee/FSPersistorManagerTests.coffee

@@ -69,14 +69,27 @@ describe "FSPersistorManagerTests", ->
         done()
 
   describe "getFileStream", ->
+    beforeEach ->
+      @opts = {}
+
     it "should use correct file location", (done) ->
-      @Fs.createReadStream.returns(
-        on:->
-      )
-      @FSPersistorManager.getFileStream @location, @name1, (err,res)=>
+      @Fs.createReadStream.returns({on: ->})
+      @FSPersistorManager.getFileStream @location, @name1, @opts, (err,res) =>
       @Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}").should.equal.true
       done()
 
+    describe "with start and end options", ->
+
+      beforeEach ->
+        @opts = {start: 0, end: 8}
+
+      it 'should pass the options to createReadStream', (done) ->
+        @Fs.createReadStream.returns({on: ->})
+        @FSPersistorManager.getFileStream @location, @name1, @opts, (err,res)=>
+        @Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}", @opts).should.equal true
+        done()
+
+
   describe "copyFile", ->
     beforeEach ->
       @ReadStream=