     name = req.params.name
     if req.doc.binary and req.doc.binary[name]
 
-        # Build stream for
+        if req.headers['range']?
+            stream.setHeader 'range', req.headers['range']
+
+        # Build stream for fetching file from the database.
         stream = db.getAttachment req.doc.binary[name].id, 'file', (err) ->
             if err and err.error = "not_found"
                 err = new Error "not found"

                next err
            else if err
                next new Error err.error

        if req.headers['range']?
            stream.setHeader 'range', req.headers['range']

        # Use streaming to avoid high memory consumption.
        stream.pipe res


            # Store the binary as an attachment of binary document.
            attachBinary = (binary) ->

            # Update binary list set on given doc then save file to CouchDB
            # as an attachment via a stream. We do not use 'file' event to
