             guard let outputStream = outputStream, let inputStream = inputStream else {
                 return
             }
-            write(false)
             dispatch_async(dispatch_queue) {
+                self.write(false)
                 while inputStream.streamStatus != .AtEnd {
                     NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 0.1));
                     NSThread.sleepForTimeInterval(0.1)

//  FPSStreamTask.swift
//  FileProvider
//
//  Created by Amir Abbas Mousavian on 5/19/95.
//
//

import Foundation

                    dR.appendData(self.dataReceived)
                    self.dataReceived.length = 0
                }
                completionHandler(dR, inputStream.streamStatus == .AtEnd, inputStream.streamError)
            }
        }
    }
