Module: storage-blob

This module contains functions that help with BLOBs. Normally BLOBs are written and read using streams, but sometimes you want to get the full BLOB into an ArrayBuffer or a Base64-encoded string.

Source:

Methods

(static) concatenateArrayBuffers(buffers) → {ArrayBuffer}

Parameters:
Name Type Description
buffers Array.<ArrayBuffer>

Concatenate an array of ArrayBuffer into a single ArrayBuffer.

Source:
Returns:

Returns an ArrayBuffer

Type: ArrayBuffer

(static) readBlobAsArrayBuffer(hash) → {Promise.<ArrayBuffer>}

Parameters:
Name Type Description
hash SHA256Hash

Reads a binary file in object storage in its entirety and returns it as ArrayBuffer. There is an equivalent write function storeArrayBufferAsBlob on WriteStorageApi objects.

Source:
Returns:

Returns an ArrayBuffer

Type: Promise.<ArrayBuffer>

(static) readBlobAsBase64(hash) → {Promise.<string>}

Parameters:
Name Type Description
hash SHA256Hash

Reads a binary file in object storage in its entirety and returns it as Base64 encoded string. There is an equivalent write function storeBase64StringAsBlob on WriteStorageApi objects.

Source:
Returns:

Returns a Base64 encoded string

Type: Promise.<string>

(static) storeArrayBufferAsBlob(arrayBuffer) → {Promise.<FileCreation>}

Parameters:
Name Type Description
arrayBuffer ArrayBuffer

Writes an ArrayBuffer to a file in object storage.

Source:
Returns:

Returns a promise that resolves with a FileCreation

Type: Promise.<FileCreation>

(static) storeBase64StringAsBlob(base64Str) → {Promise.<FileCreation>}

Parameters:
Name Type Description
base64Str string

Writes a Base64 string to a file in object storage.

Source:
Returns:

Returns a promise that resolves with a FileCreation

Type: Promise.<FileCreation>

(async, static) storeUTF8Clob(str) → {Promise.<FileCreation>}

Parameters:
Name Type Description
str string

A UTF-8 string

The string will be stored under the name resulting from calculation of a crypto-hash over the string.

This function is safe to be used in multistep asynchronous writing operations: It only writes to files using their contents' SHA-256 as filename. That means even if, as part of a parent function, we have a pattern of 1) read file, 2) process, 3) write file it is not possible to lose anything.

This function is not atomic. Its two steps of creating the SHA-256 hash and of storing the string are independent "await"-ed asynchronous operations, another store operation could take place in between, if scheduled.

Source:
Returns:

A promise with the result of the object creation.

Type: Promise.<FileCreation>