         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)
     

            streamDelegate?.urlSession?(_underlyingSession, task: self, didCompleteWithError: error)
        }
        
        if aStream == inputStream && eventCode.contains(.hasBytesAvailable) {
            while (inputStream!.hasBytesAvailable) {
                var buffer = [UInt8](repeating: 0, count: 2048)

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