# Class: BlobClient

## BlobClient

#### new BlobClient(parameters)

  Client to interact with the blob-storage.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `parameters`

  object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `logger` | object |

### Methods

#### createArtifact(name)

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

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `name` | string | Name of artifact

  ##### Returns:

  Type
    Artifact

#### getArtifact(metadataHash [, callback])

  Retrieves the Artifact from the blob storage.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `metadataHash` | hash |  | hash associated with the artifact.
  `callback` | function | <optional> | if provided no promise will be returned.

  ##### 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 [, subpath])

  Returns the get-url for downloading a blob.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `metadataHash` | string |  |
  `subpath` | string | <optional> | optional file-like path to sub-object if complex blob

  ##### Returns:

  get-url for blob

  Type
    string

#### getHumanSize(bytes [, si])

  Converts bytes to a human readable string.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `bytes` | number |  | File size in bytes.
  `si` | boolean | <optional> | If true decimal conversion will be used (by default binary is used).

  ##### Returns:

  Type
    string

#### getMetadata(metadataHash [, callback])

  Retrieves metadata from blob storage.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `metadataHash` | string |  | hash of metadata.
  `callback` | function | <optional> | if provided no promise will be returned.

  ##### 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()

  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.

  ##### Returns:

  A new instance of a BlobClient

  Type
    BlobClient

#### getObject(metadataHash [, callback] [, subpath])

  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 | Argument | 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

  ##### 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 [, callback])

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

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `metadataHash` | string |  | hash of metadata for object.
  `callback` | function | <optional> | if provided no promise will be returned.

  ##### 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 [, callback])

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

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `metadataHash` | string |  | hash of metadata for object.
  `callback` | function | <optional> | if provided no promise will be returned.

  ##### 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 [, subpath])

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

  ##### Parameters:

  Name | Type | Argument | 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

  ##### 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 [, callback])

  Adds a file to the blob storage.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `name` | string |  | file name.
  `data` | string | Buffer | ArrayBuffer |  | file content.
  `callback` | function | <optional> | if provided no promise will be returned.

  ##### 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 [, callback])

  Adds multiple files to the blob storage.

  ##### Parameters:

  Name | Type | Argument | 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.

  ##### 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( [callback])

  Saves all the artifacts associated with the current instance.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `callback` | function | <optional> | if provided no promise will be returned.

  ##### 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

#### Search results