//
//  BPDownloader.h
//  BreakPointDownload
//
//  Created by 黄亚州 on 2017/5/30.
//  Copyright © 2017年 黄亚州. All rights reserved.
//

#import <Foundation/Foundation.h>

@class BPDownloadContent;
@interface BPDownloader : NSObject

//下载会话
@property (nonatomic, strong) NSURLSession *session;
//下载所需的数据
@property (nonatomic, strong) BPDownloadContent *aContent;
/// 是否已经取消了下载
@property (nonatomic, assign) BOOL hasCancel;

//成功、失败、进度 回调
@property (nonatomic, copy) void (^successBlock)(BPDownloader *data);
@property (nonatomic, copy) void (^failBlock)(BPDownloader *data, NSError *error);
@property (nonatomic, copy) void (^downloadProgress)(int64_t completeBytes, int64_t totalBytes);

/**
 * 开始下载
 */
- (void)startDownload;
/**
 * @description 取消下载
 */
- (void)cancel;

/**
 * @description 接收下载数据
 * @param session 会话
 * @param dataTask 数据任务
 * @param data 数据
 */
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data;

/**
 * @description 下载结束
 * @param session 会话
 * @param task 任务
 * @param error 下载过程中发生的错误，如果成功 error = nil
 */
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error;

@end
