Blob

public final class Blob : Equatable, Hashable

Blob 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 Blob’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.

  • Value of type property for blob object

    Declaration

    Swift

    public static let blobType: String
  • Blob dict property containing a blobType of the data.

    Declaration

    Swift

    public static let typeProperty: String
  • Blob dict property containing a digest of the data.

    Declaration

    Swift

    public static let blobDigestProperty: String
  • Blob dict property containing a length of the data.

    Declaration

    Swift

    public static let blobLengthProperty: String
  • Blob dict property containing a content type of the data.

    Declaration

    Swift

    public static let blobContentType: String
  • Initializes a Blob with the given in-memory data.

    Declaration

    Swift

    public convenience init(contentType: String, data: Data)

    Parameters

    contentType

    The type of content this Blob will represent.

    data

    The data that this Blob will contain.

  • Initializes a Blob with the given stream of data.

    Declaration

    Swift

    public convenience init(contentType: String, contentStream: InputStream)

    Parameters

    contentType

    The type of content this Blob will represent.

    contentStream

    The stream of data that this Blob will consume.

  • Initializes a Blob with the contents of a file.

    Throws

    An error on a failure.

    Declaration

    Swift

    public convenience init(contentType: String, fileURL: URL) throws

    Parameters

    contentType

    The type of content this Blob will represent.

    fileURL

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

  • Gets the contents of a Blob as a block of memory. Not recommended for very large blobs, as it may be slow and use up lots of RAM.

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public var properties: [String : Any] { get }

Equality

  • Equal to operator for comparing two Blob objects.

    Declaration

    Swift

    public static func == (blob1: Blob, blob2: Blob) -> Bool

Hashable

  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)

toJSON

  • Returns a dictionary representation of the blob object in JSON string format. The dictionary will contain only metadata information without data. If Blob is not saved in the database which means that it doesn’t have digest information, calling toJSON() will not be allowed and it will throw an NSInternalInconsistencyException.

    Declaration

    Swift

    public func toJSON() -> String
  • Return whether the given dictionary represents Blob or not

    Declaration

    Swift

    public static func isBlob(properties: [String : Any]) -> Bool