 import Cocoa
 
 @NSApplicationMain
-class AppDelegate: NSObject, NSApplicationDelegate {
+class AppDelegate: NSObject, NSApplicationDelegate, NSStreamDelegate {
 
     @IBOutlet weak var window: NSWindow!
-
+    var stream: NSStream!
+    var buffer: NSMutableData!
 
     func applicationDidFinishLaunching(aNotification: NSNotification) {
 //        let u = NSURL(string: "http://donnees.ville.montreal.qc.ca/dataset/37450231-e4d4-4e9c-99b3-5e88afa6e053/resource/67a95c30-4e21-4346-83f7-491d4ca54a7e/download/cataloguebibliotheque.zip")!

            return nil
        }
        
        return NSFileManager.defaultManager().enumeratorAtPath(target)?.allObjects.filter({file -> Bool in
            println("Current file in extracted folder is \(file)")

            return (file as String).pathExtension == "csv"
        }).first as NSString?
    }
    
}



    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
    
    func importFile(path: String) {
        println("Importing file at path \(path)")
        
        // Opening CSV file
        let stream = NSInputStream(fileAtPath: path)!
        stream.delegate = self
        stream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
        stream.open()
    }

    func unzipAndFindCSV(file: String) -> String? {
