CBLBlob

@interface CBLBlob : NSObject

A CBLBlob contains arbitrary binary data, tagged with a MIME type. Blobs can be arbitrarily large, and their data is loaded only on demand (when the content or contentStream properties are accessed), not when the document is loaded. The document’s raw JSON form only contains the CBLBlob’s metadata (type, length and a digest of the data) in a small object. The data itself is stored externally to the document, keyed by the digest.

  • Initializes a CBLBlob with the given in-memory data.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithContentType:(nonnull NSString *)contentType
                                           data:(nonnull NSData *)data;

    Swift

    init(contentType: String, data: Data)

    Parameters

    contentType

    The type of content this CBLBlob will represent.

    data

    The data that this CBLBlob will contain.

    Return Value

    The CBLBlob object.

  • Initializes a CBLBlob with the given stream of data.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithContentType:(nonnull NSString *)contentType
                                  contentStream:(nonnull NSInputStream *)stream;

    Swift

    init(contentType: String, contentStream stream: InputStream)

    Parameters

    contentType

    The type of content this CBLBlob will represent.

    stream

    The stream of data that this CBLBlob will consume.

    Return Value

    The CBLBlob object.

  • Initializes a CBLBlob with the contents of a file.

    Declaration

    Objective-C

    - (nullable instancetype)initWithContentType:(nonnull NSString *)contentType
                                         fileURL:(nonnull NSURL *)fileURL
                                           error:
                                               (NSError *_Nullable *_Nullable)error;

    Swift

    init(contentType: String, fileURL: URL) throws

    Parameters

    contentType

    The type of content this CBLBlob will represent.

    fileURL

    A URL to a file containing the data that this CBLBlob will represent.

    error

    On return, the error if any.

    Return Value

    The CBLBlob object.

  • The -init method is not available.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Gets the contents of a CBLBlob as a block of memory. Not recommended for very large blobs, as it may be slow and use up lots of RAM.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSData *content;

    Swift

    var content: Data? { get }
  • A stream of the content of a CBLBlob. The caller is responsible for opening the stream, and closing it when finished.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSInputStream *contentStream;

    Swift

    var contentStream: InputStream? { get }
  • The type of content this CBLBlob represents; by convention this is a MIME type.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSString *contentType;

    Swift

    var contentType: String? { get }
  • The binary length of this CBLBlob.

    Declaration

    Objective-C

    @property (readonly, nonatomic) uint64_t length;

    Swift

    var length: UInt64 { get }
  • The cryptographic digest of this CBLBlob’s contents, which uniquely identifies it.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSString *digest;

    Swift

    var digest: String? { get }
  • The metadata associated with this CBLBlob

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        NSDictionary<NSString *, id> *_Nonnull properties;

    Swift

    var properties: [String : Any] { get }