<commit_before>//
//  MultipartFile.swift
//  blackfish
//
//  Created by <NAME> on 03/02/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

struct MultipartFile {
    
    let name: String
    
    let data: [UInt8]
    
}<commit_msg>Added in saving to temp directory and path for Multipart files<commit_after>//
//  MultipartFile.swift
//  blackfish
//
//  Created by <NAME> on 03/02/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
#if os(Linux)
    import Glibc
#endif

enum FileError: ErrorType {
    case WriteError
}

struct MultipartFile {
    
    let name: String
    
    let data: [UInt8]
    
    func saveToTemporaryDirectory(filename: String, completion: ((path: String?, error: ErrorType?) -> Void)) {
        let path = NSTemporaryDirectory() + "\(filename)"
        saveToPath(path, completion: completion)
    }
    
    func saveToPath(path: String, completion: ((path: String?, error: ErrorType?) -> Void)) {
    
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) {
            
            let raw = NSData(bytesNoCopy: UnsafeMutablePointer<Void>(self.data),
                length: self.data.count * sizeof(UInt8), freeWhenDone: false)
            
            if raw.writeToFile(path, atomically: true) {
                
                completion(path: path, error: nil)
                
            } else {
                
                completion(path: nil, error: FileError.WriteError)
            }
        }
    }
    
}
{'fraction_non_alphanumeric': 0.11031331592689295, 'fraction_numerical': 0.018276762402088774, 'mean_word_length': 2.066, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '939021', 'n_tokens_mistral': 483, 'n_tokens_neox': 451, 'n_words': 117}