mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
8 years ago
|
//
|
||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
// A protocol that abstracts away a source of NSData
|
||
|
// and allows us to:
|
||
|
//
|
||
|
// * Lazy-load if possible.
|
||
|
// * Avoid duplicate reads & writes.
|
||
|
@protocol DataSource
|
||
|
|
||
|
// Should not be called unless necessary as it can involve an expensive read.
|
||
|
- (NSData *)data;
|
||
|
|
||
|
// The URL for the data. Should always be a File URL.
|
||
|
//
|
||
|
// Should not be called unless necessary as it can involve an expensive write.
|
||
|
//
|
||
|
// Will only return nil in the error case.
|
||
|
//
|
||
|
// TODO: Try to remove the parameter.
|
||
|
- (nullable NSURL *)dataUrl:(NSString *)fileExtension;
|
||
|
|
||
|
// The file path for the data.
|
||
|
//
|
||
|
// Should not be called unless necessary as it can involve an expensive write.
|
||
|
//
|
||
|
// Will only return nil in the error case.
|
||
|
//
|
||
|
// TODO: Try to remove the parameter.
|
||
|
- (nullable NSString *)dataPath:(NSString *)fileExtension;
|
||
|
|
||
|
// The file path for the data, if it already exists on disk.
|
||
|
//
|
||
|
// This method is safe to call as it will not do any expensive reads or writes.
|
||
|
//
|
||
|
// May return nil if the data does not reside on disk.
|
||
|
- (nullable NSString *)dataPathIfOnDisk;
|
||
|
|
||
|
// Will return zero in the error case.
|
||
|
- (NSUInteger)dataLength;
|
||
|
|
||
|
@end
|
||
|
|
||
|
#pragma mark -
|
||
|
|
||
|
@interface DataSourceValue : NSObject <DataSource>
|
||
|
|
||
|
+ (nullable id<DataSource>)dataSourceWithData:(NSData *)data;
|
||
|
|
||
|
+ (id<DataSource>)emptyDataSource;
|
||
|
|
||
|
@end
|
||
|
|
||
|
#pragma mark -
|
||
|
|
||
|
@interface DataSourcePath : NSObject <DataSource>
|
||
|
|
||
|
+ (nullable id<DataSource>)dataSourceWithURL:(NSURL *)fileUrl;
|
||
|
|
||
|
+ (nullable id<DataSource>)dataSourceWithFilePath:(NSString *)filePath;
|
||
|
|
||
|
@end
|
||
|
|
||
|
//#pragma mark -
|
||
|
//
|
||
|
//@interface DataSourceURL : NSObject <DataSource>
|
||
|
//
|
||
|
//+ (id<DataSource>)dataSourceWithURL:(NSURL *)fileUrl;
|
||
|
//
|
||
|
//@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|