// // Copyright 2017 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only // NS_ASSUME_NONNULL_BEGIN @class ImageMetadata; // A base class that abstracts away a source of NSData // and allows us to: // // * Lazy-load if possible. // * Avoid duplicate reads & writes. @protocol DataSource @property (nonatomic, nullable) NSString *sourceFilename; // Should not be called unless necessary as it can involve an expensive read. @property (nonatomic, readonly) 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. @property (nonatomic, readonly, nullable) NSURL *dataUrl; // Will return zero in the error case. @property (nonatomic, readonly) NSUInteger dataLength; @property (nonatomic, readonly) BOOL isValidImage; @property (nonatomic, readonly) BOOL isValidVideo; @property (nonatomic, readonly) BOOL hasStickerLikeProperties; @property (nonatomic, readonly) ImageMetadata *imageMetadata; // Returns YES on success. - (BOOL)writeToUrl:(NSURL *)dstUrl error:(NSError **)error; // Faster than `writeToUrl`, but a DataSource can only be moved once, // and cannot be used after it's been moved. - (BOOL)moveToUrlAndConsume:(NSURL *)dstUrl error:(NSError **)error; @end #pragma mark - @interface DataSourceValue : NSObject + (_Nullable id)dataSourceWithData:(NSData *)data fileExtension:(NSString *)fileExtension; + (_Nullable id)dataSourceWithData:(NSData *)data utiType:(NSString *)utiType; + (_Nullable id)dataSourceWithData:(NSData *)data mimeType:(NSString *)mimeType; + (_Nullable id)dataSourceWithOversizeText:(NSString *_Nullable)text; + (id)emptyDataSource; @end #pragma mark - @interface DataSourcePath : NSObject + (_Nullable id)dataSourceWithURL:(NSURL *)fileUrl shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation error:(NSError **)error; + (_Nullable id)dataSourceWithFilePath:(NSString *)filePath shouldDeleteOnDeallocation:(BOOL)shouldDeleteOnDeallocation error:(NSError **)error; + (_Nullable id)dataSourceWritingTempFileData:(NSData *)data fileExtension:(NSString *)fileExtension error:(NSError **)error; + (_Nullable id)dataSourceWritingSyncMessageData:(NSData *)data error:(NSError **)error; @end NS_ASSUME_NONNULL_END