 
 final class UploadDataTask: Task {
     
-//    let chunk: Data
-    let url: URL
+    let filePath: URL
     let range: Range<Int>
     let uploader: Uploader
     
-    init(url: URL, range: Range<Int>, uploader: Uploader) {
-        self.url = url
+    init(filePath: URL, range: Range<Int>, uploader: Uploader) {
+        self.filePath = filePath
         self.range = range
         self.uploader = uploader
     }
     
     func run(completed: @escaping ([Task]) -> ()) {
         // TODO: Error handling
-        let data = try! Data(contentsOf: url)
+        let data = try! Data(contentsOf: filePath)
         let sub = data[range]
         
         uploader.upload(data: sub, range: range) {

        // TODO: error handling
        
        // Store file now
        let url = try! Files.store(data: data)
        let sizeInKiloBytes = 500 * 1024// Uses safe speed, 500kb
        let ranges = data.chunkRanges(size: sizeInKiloBytes)
        scheduleUploadsFor(url: url, ranges: ranges)
    }
    
    private func scheduleUploadsFor(url: URL, ranges: [Range<Int>]) {
        let tasks = ranges.map { range in
            UploadDataTask(url: url, range: range, uploader: Uploader())
        }
        
        total += tasks.count
        scheduler.addGroupedTasks(tasks: tasks)
    }

    /// Get Data based on URL
    /// - Parameter url: The target url to load data from
    /// - Throws: Throws TUSClientError
    /// - Returns: The loaded Data
    private func findData(for url: URL) throws -> Data {
        do {
            return try Data(contentsOf: url)
        } catch {
            let prefixedPath = "file://" + url.absoluteString
            let url = try URL(string:prefixedPath).or(willThrow: TUSClientError.fileNotFound)
            let data = try? Data(contentsOf: url)
            return try data.or(willThrow: TUSClientError.fileNotFound)
        }
    }
}

extension TUSClient: SchedulerDelegate {

    /// - Throws: TUSClientError
    public func uploadFileAt(filePath: URL) throws {
        do {
            let destinationFilePath = try Files.copy(from: filePath)
            let size = try destinationFilePath.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? Data(contentsOf: destinationFilePath).count
            
            // TODO: Duplicate size
            let sizeInKiloBytes = 500 * 1024// Uses safe speed, 500kb
            let ranges = (0..<size).chunkRanges(size: sizeInKiloBytes)
            
            scheduleUploadsFor(filePath: destinationFilePath, ranges: ranges)
        } catch {
            throw TUSClientError.couldNotCopyFile
        }
    }
    
    /// Upload data
