add .gitignore

This commit is contained in:
JoyWayer
2023-12-27 20:38:37 +08:00
parent b106a628a5
commit f6343426d6
515 changed files with 104217 additions and 199 deletions

View File

@@ -0,0 +1,52 @@
//
// QNFileRecorder.h
// QiniuSDK
//
// Created by bailong on 14/10/5.
// Copyright (c) 2014年 Qiniu. All rights reserved.
//
#import "QNRecorderDelegate.h"
#import <Foundation/Foundation.h>
/**
* 将上传记录保存到文件系统中
*/
@interface QNFileRecorder : NSObject <QNRecorderDelegate>
/**
* 用指定保存的目录进行初始化
*
* @param directory 目录
* @param error 输出的错误信息
*
* @return 实例
*/
+ (instancetype)fileRecorderWithFolder:(NSString *)directory
error:(NSError *__autoreleasing *)error;
/**
* 用指定保存的目录以及是否进行base64编码进行初始化
*
* @param directory 目录
* @param encode 为避免因为特殊字符或含有/无法保存持久化记录故用此参数指定是否要base64编码
* @param error 输出错误信息
*
* @return 实例
*/
+ (instancetype)fileRecorderWithFolder:(NSString *)directory
encodeKey:(BOOL)encode
error:(NSError *__autoreleasing *)error;
/**
* 从外部手动删除记录,如无特殊需求,不建议使用
*
* @param key 持久化记录key
* @param dir 目录
* @param encode 是否encode
*/
+ (void)removeKey:(NSString *)key
directory:(NSString *)dir
encodeKey:(BOOL)encode;
@end

View File

@@ -0,0 +1,99 @@
//
// QNFileRecorder.m
// QiniuSDK
//
// Created by bailong on 14/10/5.
// Copyright (c) 2014 Qiniu. All rights reserved.
//
#import "QNFileRecorder.h"
#import "QNUrlSafeBase64.h"
@interface QNFileRecorder ()
@property (copy, readonly) NSString *directory;
@property BOOL encode;
@end
@implementation QNFileRecorder
- (NSString *)pathOfKey:(NSString *)key {
return [QNFileRecorder pathJoin:key path:_directory];
}
+ (NSString *)pathJoin:(NSString *)key
path:(NSString *)path {
return [[NSString alloc] initWithFormat:@"%@/%@", path, key];
}
+ (instancetype)fileRecorderWithFolder:(NSString *)directory
error:(NSError *__autoreleasing *)perror {
return [QNFileRecorder fileRecorderWithFolder:directory encodeKey:false error:perror];
}
+ (instancetype)fileRecorderWithFolder:(NSString *)directory
encodeKey:(BOOL)encode
error:(NSError *__autoreleasing *)perror {
NSError *error;
[[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&error];
if (error != nil) {
if (perror) {
*perror = error;
}
return nil;
}
return [[QNFileRecorder alloc] initWithFolder:directory encodeKey:encode];
}
- (instancetype)initWithFolder:(NSString *)directory encodeKey:(BOOL)encode {
if (self = [super init]) {
_directory = directory;
_encode = encode;
}
return self;
}
- (NSError *)set:(NSString *)key
data:(NSData *)value {
NSError *error;
if (_encode) {
key = [QNUrlSafeBase64 encodeString:key];
}
[value writeToFile:[self pathOfKey:key] options:NSDataWritingAtomic error:&error];
return error;
}
- (NSData *)get:(NSString *)key {
if (_encode) {
key = [QNUrlSafeBase64 encodeString:key];
}
return [NSData dataWithContentsOfFile:[self pathOfKey:key]];
}
- (NSError *)del:(NSString *)key {
NSError *error;
if (_encode) {
key = [QNUrlSafeBase64 encodeString:key];
}
[[NSFileManager defaultManager] removeItemAtPath:[self pathOfKey:key] error:&error];
return error;
}
+ (void)removeKey:(NSString *)key
directory:(NSString *)dir
encodeKey:(BOOL)encode {
if (encode) {
key = [QNUrlSafeBase64 encodeString:key];
}
NSError *error;
NSString *path = [QNFileRecorder pathJoin:key path:dir];
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, dir: %@>", NSStringFromClass([self class]), self, _directory];
}
@end

View File

@@ -0,0 +1,55 @@
//
// QNRecorderDelegate.h
// QiniuSDK
//
// Created by bailong on 14/10/5.
// Copyright (c) 2014年 Qiniu. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
* 为持久化上传记录根据上传的key以及文件名 生成持久化的记录key
*
* @param uploadKey 上传的key
* @param filePath 文件名
*
* @return 根据uploadKey, filepath 算出的记录key
*/
typedef NSString * (^QNRecorderKeyGenerator)(NSString *uploadKey, NSString *filePath);
/**
* 持久化记录接口,可以实现将记录持久化到文件,数据库等
*/
@protocol QNRecorderDelegate <NSObject>
/**
* 保存记录
*
* @param key 持久化记录的key
* @param value 持久化记录上传状态信息
*
* @return 错误信息成功为nil
*/
- (NSError *)set:(NSString *)key
data:(NSData *)value;
/**
* 取出保存的持久化上传状态信息
*
* @param key 持久化记录key
*
* @return 上传中间状态信息
*/
- (NSData *)get:(NSString *)key;
/**
* 删除持久化记录,一般在上传成功后自动调用
*
* @param key 持久化记录key
*
* @return 错误信息成功为nil
*/
- (NSError *)del:(NSString *)key;
@end