         return FileProviderStreamTask.streamTasks[_taskIdentifier]
     }
     
+    /// The end of the stream has been reached.
+    private var endEncountered: Bool = false
+    
     /// Trust all certificates if `disableEvaluation`, Otherwise validate certificate chain.
     public var serverTrustPolicy: ServerTrustPolicy = .performDefaultEvaluation(validateHost: true)
     

                timedOut = expireDate < Date()
                self.dataReceivedLock.lock()
            }
            var dR: Data?
            if self.dataReceived.count > maxBytes {
                let range: Range = 0..<maxBytes

        dispatch_queue.async {
            var timedOut: Bool = false
            self.dataReceivedLock.lock()
            while (self.dataReceived.count == 0 || self.dataReceived.count < minBytes) && !timedOut && !self.endEncountered {
                self.dataReceivedLock.unlock()
                Thread.sleep(forTimeInterval: 0.1)
                if let error = inputStream.streamError {
