Module: cpb-storage/file

Low-level Cloud Storage File operations

Source:

Methods

(async, static) delete(bucketopt, nullable, namenon-null, generationopt, nullable) → {Promise.<void>}

Delete File or File Version from bucket

Parameters:
Name Type Attributes Default Description
bucket string <optional>
<nullable>
process.env.BUCKET || 'custom-product-builder'

storage bucket

name string

filepath to delete

generation number <optional>
<nullable>

file generation; if given only that file version will be deleted

Source:
Returns:
Type
Promise.<void>

(async, static) read(bucketopt, nullable, namenon-null, jsonopt, nullable, generationnullable) → {Promise.<(string|object|undefined)>}

Read file from the storage bucket.

Returns parsed file content if json flag is set. Otherwise returns string or undefined.
THIS METHOD DOESNT THROW ANY EXCEPTIONS EXTERNALLY

Parameters:
Name Type Attributes Default Description
bucket string <optional>
<nullable>
process.env.BUCKET || 'custom-product-builder'

storage bucket

name string

file path within bucket

json * <optional>
<nullable>
true

return content as json object

generation number <nullable>

file version generation to read

Source:
Throws:
  • TypeError.<bucket>
  • TypeError.<name>
  • TypeError.<result>
Returns:

contents - file contents as string or json

Type
Promise.<(string|object|undefined)>

(async, static) upload(bucketopt, nullable, namenon-null, datanon-null, contentTypeopt, nullable, callbackopt, nullable, metadataopt, nullable) → {Promise.<void>}

###streaming file upload

Parameters:
Name Type Attributes Default Description
bucket string <optional>
<nullable>
process.env.BUCKET || 'custom-product-builder'

storage bucket

name string

filename for the uploaded file in bucket

data *

data to be uploaded

contentType string <optional>
<nullable>
'application/json'

file content type

callback function <optional>
<nullable>
metadata object <optional>
<nullable>
{}

file metadata

Source:
Returns:
Type
Promise.<void>