jina.types.document.mixins.convert module

class jina.types.document.mixins.convert.ConvertMixin[source]

Bases: object

Provide helper functions for Document to support conversion between blob, text and buffer.

convert_buffer_to_blob(dtype=None, count=- 1, offset=0)[source]

Assuming the buffer is a _valid_ buffer of Numpy ndarray, set blob accordingly.

Parameters
  • dtype (Optional[str]) – Data-type of the returned array; default: float.

  • count (int) – Number of items to read. -1 means all data in the buffer.

  • offset (int) – Start reading the buffer from this offset (in bytes); default: 0.

Return type

~T

Returns

itself after processed

convert_blob_to_buffer()[source]

Convert blob to buffer inplace.

Return type

~T

Returns

itself after processed

convert_uri_to_datauri(charset='utf-8', base64=False)[source]

Convert uri to dataURI and store it in uri inplace.

Parameters
  • charset (str) – charset may be any character set registered with IANA

  • base64 (bool) – used to encode arbitrary octet sequences into a form that satisfies the rules of 7bit. Designed to be efficient for non-text 8 bit and binary data. Sometimes used for text data that frequently uses non-US-ASCII characters.

Return type

~T

Returns

itself after processed