ZDCFileReader

@interface ZDCFileReader : NSObject

The FileReader class provides random access to an encrypted file.

That is, it allows you to open an encrypted file on disk, and read from that file (using random access) as if the file were cleartext (not encrypted).

  • Initializes a new FileReader with the encapsulated information from the cryptoFile instance.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithCryptoFile:(nonnull ZDCCryptoFile *)cryptoFile;

    Swift

    init(cryptoFile: ZDCCryptoFile)
  • Designated initializer.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithFileURL:(nonnull NSURL *)fileURL
                                     format:(ZDCCryptoFileFormat)format
                              encryptionKey:(nonnull NSData *)encryptionKey
                                retainToken:(nullable id)retainToken;

    Swift

    init(fileURL: URL, format: ZDCCryptoFileFormat, encryptionKey: Data, retainToken: Any?)
  • This property is available anytime after the stream has been opened.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, nullable) NSNumber *cleartextFileSize;

    Swift

    var cleartextFileSize: NSNumber? { get }
  • Attempts to open the underlying file on disk.

    @return YES if the file was successfully opened. NO otherwise.

    Declaration

    Objective-C

    - (BOOL)openFileWithError:(NSError *_Nullable *_Nullable)errorOut;

    Swift

    func openFile() throws

    Parameters

    errorOut

    Pass a non-nil error pointer to receive the reason for an error.

    • - parameter: buffer
    • An allocated buffer where the read bytes are to be stored.
    • The buffer must be at least as big as range.length.
    • - parameter: range
    • The range of the data to read.
    • This range is expressed as if the underlying file was cleartext.
    • That is, you don’t have to worry about the encryption stuff - all translation is done for you.
    • - parameter: errorOut
    • If the returned value is negative, this will contain the error that occurred.

    Declaration

    Objective-C

    - (ssize_t)getBytes:(nonnull void *)buffer
                  range:(NSRange)range
                  error:(NSError *_Nullable *_Nullable)errorOut;

    Swift

    func getBytes(_ buffer: UnsafeMutableRawPointer, range: NSRange, error errorOut: NSErrorPointer) -> Int
  • Optional manual close method. Underlying stream will automatically close if ZDCFileReader is deallocated.

    Declaration

    Objective-C

    - (void)close;

    Swift

    func close()