<commit_before>import Foundation

public typealias DownloaderDataCompletion = (_ statusCode: Int, _ responseData: Data?, _ error: Error?) -> Void

/// A wrapper for `URLSession` similar to `WebAPI` for general purpose
/// downloading of data and images.
open class Downloader {
    fileprivate static let twentyFiveMB: Int = (1024 * 1024 * 25)
    fileprivate static let twoHundredMB: Int = (1024 * 1024 * 200)
    
    public enum Errors: Error {
        case invalidBaseURL
        
        public var localizedDescription: String {
            return "Invalid Base URL: You can not use a `path` method without specifiying a baseURL."
        }
    }
    
    fileprivate lazy var session: URLSession = {
        [unowned self] in
        let configuration = URLSessionConfiguration.default
        configuration.urlCache = self.cache
        configuration.requestCachePolicy = .returnCacheDataElseLoad
        return URLSession(configuration: configuration, delegate: nil, delegateQueue: nil)
    }()
    fileprivate var cache: URLCache = URLCache(memoryCapacity: Downloader.twentyFiveMB, diskCapacity: Downloader.twoHundredMB, diskPath: "Downloader")
    public var baseURL: URL?
    public var timeout: TimeInterval = 20
    
    public init() {
    }
    
    public convenience init(baseURL: URL) {
        self.init()
        self.baseURL = baseURL
    }
    
    internal func urlForPath(_ path: String) -> URL? {
        guard let baseURL = self.baseURL else {
            return nil
        }
        
        return baseURL.appendingPathComponent(path)
    }
    
    open func getDataAtPath(_ path: String, cachePolicy: URLRequest.CachePolicy, completion: @escaping DownloaderDataCompletion) {
        guard let url = self.urlForPath(path) else {
            completion(0, nil, Errors.invalidBaseURL)
            return
        }
        
        self.getDataAtURL(url, cachePolicy: cachePolicy, completion: completion)
    }<commit_msg>Updated Downloader with UIKitForMac specific deprecations.<commit_after>import Foundation

public typealias DownloaderDataCompletion = (_ statusCode: Int, _ responseData: Data?, _ error: Error?) -> Void

/// A wrapper for `URLSession` similar to `WebAPI` for general purpose
/// downloading of data and images.
open class Downloader {
    fileprivate static let twentyFiveMB: Int = (1024 * 1024 * 25)
    fileprivate static let twoHundredMB: Int = (1024 * 1024 * 200)
    
    public enum Errors: Error {
        case invalidBaseURL
        
        public var localizedDescription: String {
            return "Invalid Base URL: You can not use a `path` method without specifiying a baseURL."
        }
    }
    
    fileprivate lazy var session: URLSession = {
        [unowned self] in
        let configuration = URLSessionConfiguration.default
        configuration.urlCache = self.cache
        configuration.requestCachePolicy = .returnCacheDataElseLoad
        return URLSession(configuration: configuration, delegate: nil, delegateQueue: nil)
    }()
    #if os(UIKitForMac)
    fileprivate var cache: URLCache = URLCache(memoryCapacity: Downloader.twentyFiveMB, diskCapacity: Downloader.twoHundredMB)
    #else
    fileprivate var cache: URLCache = URLCache(memoryCapacity: Downloader.twentyFiveMB, diskCapacity: Downloader.twoHundredMB, diskPath: "Downloader")
    #endif
    public var baseURL: URL?
    public var timeout: TimeInterval = 20
    
    public init() {
    }
    
    public convenience init(baseURL: URL) {
        self.init()
        self.baseURL = baseURL
    }
    
    internal func urlForPath(_ path: String) -> URL? {
        guard let baseURL = self.baseURL else {
            return nil
        }
        
        return baseURL.appendingPathComponent(path)
    }
    
    open func getDataAtPath(_ path: String, cachePolicy: URLRequest.CachePolicy, completion: @escaping DownloaderDataCompletion) {
        guard let url = self.urlForPath(path) else {
            completion(0, nil, Errors.invalidBaseURL)
            return
        }
        
        self.getDataAtURL(url, cachePolicy: cachePolicy, completion: completion)
    }
{'fraction_non_alphanumeric': 0.076026232693709, 'fraction_numerical': 0.011658974981782852, 'mean_word_length': 2.7572992700729926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1039183', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1079, 'n_words': 337}