Skip to content

A tiny library makes uploading and downloading easier

License

Notifications You must be signed in to change notification settings

yuvalt/Transporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Platform Language License Issues

Features

  • multiple files (parallel, serial)
  • background uploads and downloads
  • progress tracking
  • retry
  • timeout
  • header settings

Quick example

let path = NSBundle.mainBundle().pathForResource("bigfile", ofType: "zip")
let fileUrl = NSURL(fileURLWithPath: path!)!

let task = UploadTask(url: "http://server.com", file: fileUrl)
	.progress { sent, total in
		let per = Double(sent) / Double(total)
		println("uploading: \(per)")
	}
	.completed { response, _, error in
		println("completed")
	}

 
 Transporter.add(task1 <--> task2 <--> task3)                     // concurrent tasks
            .progress { bytes, total in
                let per = Double(bytes) / Double(total)
                println("serial tasks: \(per)")
            }
            .completed {
                println("task1, task2, task3: completed")
            }
            .add(task4 --> task5 --> task6)                       // serial tasks 
            .progress { bytes, total in
                println("concurrent tasks")
            }
            .resume()

Usage

// downloading task

let task = DownloadTask(url: downloadUrl, destination: des)
	.progress { bytes, total in
		let per = Double(bytes) / Double(total)
		println("downloading: \(per)")
	}
	.completed { response, json, error in
		println("completed")
	}


// uploading task
// upload types: File, Data, Stream

let task = UploadTask(url: "http://server.com", data: uploadData)
	.progress { sent, total in
		let per = Double(sent) / Double(total)
		println("uploading: \(per)")
	}
	.completed { response, _, error in
		println("completed")
	}


// task

task.headers = ["key": "value"]
task.params = ["key": "value"]
task.pause()
task.cancel()
task.retry

// background handling
// add the following method in the app delegate

func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
	Transporter.handleEventsForBackgroundURLSection(identifier, completionHandler: completionHandler)
    }


// Transporter configurations

Transporter.headers = [key: value]
Transporter.timeoutIntervalForRequest = 30.0
Transporter.timeoutIntervalForResource = 60.0
Transporter.HTTPMaximumconnectionsPerHost = 5
			

Installation

  • Installation with CocoaPods
	// coming soon
  • Copying all the files into your project
  • Using submodule

Requirements

  • iOS 7.0+
  • Xcode 6.1

License

Transporter is released under the MIT license. See LICENSE for details.

About

A tiny library makes uploading and downloading easier

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.0%
  • Ruby 2.0%