Class: BlobClient

BlobClient(parameters)

new BlobClient(parameters)

Client to interact with the blob-storage.

Parameters:
Name Type Description
parameters object
Properties
Name Type Description
logger object
Source:

Methods

createArtifact(name) → {Artifact}

Creates a new artifact and adds it to array of artifacts of the instance.

Parameters:
Name Type Description
name string

Name of artifact

Source:
Returns:
Type
Artifact

getArtifact(metadataHash, callbackopt) → {external:Promise}

Retrieves the Artifact from the blob storage.

Parameters:
Name Type Attributes Description
metadataHash hash

hash associated with the artifact.

callback function <optional>

if provided no promise will be returned.

Source:
Returns:

On success the promise will be resolved with Artifact artifact.
On error the promise will be rejected with Error error.

Type
external:Promise

getDownloadURL(metadataHash, subpathopt) → {string}

Returns the get-url for downloading a blob.

Parameters:
Name Type Attributes Description
metadataHash string
subpath string <optional>

optional file-like path to sub-object if complex blob

Source:
Returns:

get-url for blob

Type
string

getHumanSize(bytes, siopt) → {string}

Converts bytes to a human readable string.

Parameters:
Name Type Attributes Description
bytes number

File size in bytes.

si boolean <optional>

If true decimal conversion will be used (by default binary is used).

Source:
Returns:
Type
string

getMetadata(metadataHash, callbackopt) → {external:Promise}

Retrieves metadata from blob storage.

Parameters:
Name Type Attributes Description
metadataHash string

hash of metadata.

callback function <optional>

if provided no promise will be returned.

Source:
Returns:

On success the promise will be resolved with {object} metadata.
On error the promise will be rejected with Error error.

Type
external:Promise

getNewInstance() → {BlobClient}

Creates and returns a new instance of a BlobClient with the same settings as the current one. This can be used to avoid issues with the artifacts being book-kept at the instance.

Source:
Returns:

A new instance of a BlobClient

Type
BlobClient

getObject(metadataHash, callbackopt, subpathopt) → {external:Promise}

Retrieves object from blob storage as a Buffer under node and as an ArrayBuffer in the client. N.B. if the retrieved file is a json-file and running in a browser, the content will be decoded and the string parsed as a JSON.

Parameters:
Name Type Attributes Description
metadataHash string

hash of metadata for object.

callback function <optional>

if provided no promise will be returned.

subpath string <optional>

optional file-like path to sub-object if complex blob

Source:
Returns:

On success the promise will be resolved with {Buffer|ArrayBuffer|object} content.
On error the promise will be rejected with Error error.

Type
external:Promise

getObjectAsJSON(metadataHash, callbackopt) → {external:Promise}

Retrieves object from blob storage and parses the content as a JSON. (Will resolve with error if not valid JSON.)

Parameters:
Name Type Attributes Description
metadataHash string

hash of metadata for object.

callback function <optional>

if provided no promise will be returned.

Source:
Returns:

On success the promise will be resolved with {object} contentJSON.
On error the promise will be rejected with Error error.

Type
external:Promise

getObjectAsString(metadataHash, callbackopt) → {external:Promise}

Retrieves object from blob storage and parses the content as a string.

Parameters:
Name Type Attributes Description
metadataHash string

hash of metadata for object.

callback function <optional>

if provided no promise will be returned.

Source:
Returns:

On success the promise will be resolved with {string} contentString.
On error the promise will be rejected with Error error.

Type
external:Promise

getStreamObject(metadataHash, writeStream, subpathopt)

If running under nodejs and getting large objects use this method to pipe the downloaded object to your provided writeStream.

Parameters:
Name Type Attributes Description
metadataHash string

hash of metadata for object.

writeStream stream.Writable

stream the requested data will be piped to.

subpath string <optional>

optional file-like path to sub-object if complex blob

Source:
Example
// Piping object to the filesystem..
var writeStream = fs.createWriteStream('my.zip');

writeStream.on('error', function (err) {
  // handle error
});

writeStream.on('finish', function () {
  // my.zip exists at this point
});

blobClient.getStreamObject(metadataHash, writeStream);

putFile(name, data, callbackopt) → {external:Promise}

Adds a file to the blob storage.

Parameters:
Name Type Attributes Description
name string

file name.

data string | Buffer | ArrayBuffer | stream.Readable

file content. !ReadStream currently only available from a nodejs setting

callback function <optional>

if provided no promise will be returned.

Source:
Returns:

On success the promise will be resolved with {string} metadataHash.
On error the promise will be rejected with Error error.

Type
external:Promise

putFiles(o, callbackopt) → {external:Promise}

Adds multiple files to the blob storage.

Parameters:
Name Type Attributes Description
o object.<string, (string|Buffer|ArrayBuffer)>

Keys are file names and values the content.

callback function <optional>

if provided no promise will be returned.

Source:
Returns:

On success the promise will be resolved with {object} fileNamesToMetadataHashes.
On error the promise will be rejected with Error error.

Type
external:Promise

saveAllArtifacts(callbackopt) → {external:Promise}

Saves all the artifacts associated with the current instance.

Parameters:
Name Type Attributes Description
callback function <optional>

if provided no promise will be returned.

Source:
Returns:

On success the promise will be resolved with {string[]} artifactHashes (metadataHashes).
On error the promise will be rejected with Error error.

Type
external:Promise