123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // mixDownloadOperation.h
- // 双子星云手机
- //
- // Created by xd h on 2024/6/27.
- //
- #import <Foundation/Foundation.h>
- #import "mixDownloadCacheManager.h"
- extern NSString * _Nullable const mixDownloadCompleteNoti;
- typedef void(^mixReceiveResponseOperation)(NSString *filePath);
- typedef void(^mixReceivDataOperation)(NSInteger completeSize,NSInteger expectSize);
- typedef void(^mixCompleteOperation)(NSDictionary *respose,NSError *error);
- /** 下载状态*/
- typedef enum : NSUInteger {
- DownloadStateWaiting = 0, /** 下载等待中 */
- DownloadStateDoing, /** 下载中 */
- DownloadStateSuspended, /** 下载暂停 */
- DownloadStateCompleted, /** 下载完成 */
- DownloadStateFailed, /** 下载失败 */
- } MixDownloadStateType;
- NS_ASSUME_NONNULL_BEGIN
- @protocol mixDownloadOperationProtocol <NSObject>
-
- // 供queue管理方法
- // 处理响应值
- - (void)operateWithResponse:(NSURLResponse *)response;
- // 处理接收到的碎片
- - (void)operateWithReceivingData:(NSData *)data;
- // 处理完成回调
- - (void)operateWithComplete:(NSError *)error;
- /**
- 设置block回调
- @param didReceiveResponse 开始下载的回调
- @param didReceivData 接收到下载的回调
- @param didComplete 下载完成的回调
- */
- - (void)configCallBacksWithDidReceiveResponse:(mixReceiveResponseOperation)didReceiveResponse
- didReceivData:(mixReceivDataOperation)didReceivData
- didComplete:(mixCompleteOperation)didComplete;
- @end
- @interface mixDownloadOperation : NSObject <mixDownloadOperationProtocol>
- /** 绑定的标示及task的创建 */
- @property (readonly,nonatomic, copy)NSString *url;
- /** 下载任务 */
- @property (nonatomic,strong)NSURLSessionDataTask *dataTask;
- /** 文件句柄 可以记录文件的下载的位置 */
- @property (nonatomic,strong) NSFileHandle *handle;
- /** 下载的文件总大小 */
- @property (nonatomic,assign) int64_t totalSize;
- /** 当前下载了多少 */
- @property (nonatomic,assign) int64_t currentSize;
- /** 当前下载文件名称 */
- @property (nonatomic,copy) NSString *fileName;
- /** 当前下载文件沙盒全路径 */
- @property (nonatomic,copy) NSString *fullPath;
- /** 文件下载状态 */
- @property (nonatomic,assign) MixDownloadStateType downloadState;
- /** 下载完成-时间戳 */
- @property (nonatomic,assign) NSInteger timeStamp;
- /** 文件类型 */
- @property (nonatomic,assign) NSInteger fileType;
- /** 是否完成 */
- @property (nonatomic, assign) NSInteger isFinished;
- // 创建下载操作任务
- - (instancetype)initWith:(NSString *)url session:(NSURLSession *)session;
- - (NSDictionary *)downLoadInfoWithFinished:(BOOL)finished;
- @end
- NS_ASSUME_NONNULL_END
|