@datadesk/delivery v0.1.0
@datadesk/delivery is a way to push and pull assets to and from S3 the Data Desk way!
Installation
@datadesk/delivery is available via npm.
npm install -D @datadesk/deliveryUsage
TK TK
API
Table of Contents
Delivery
Extends EventEmitter
The base class for @datadesk/delivery. Create an instance of Delivery to set an interface with S3.
Parameters
options{bucket: string, basePath: string}options.bucketThe bucket on S3 to interact withoptions.basePathA pre-defined base path for all interactions with S3. Useful for establishing the slug or prefix of an upload. (optional, default'')
Examples
const delivery = new Delivery({
bucket: 'apps.thebignews.com',
basePath: 'our-great-project',
});uploadFile
Uploads a single file to S3.
Parameters
filestring The path to the file to uploadpathstring Where to upload the file relative to the base pathoptions{isPublic: boolean?, shouldCache: boolean?} (optional, default{})options.isPublicWhether a file should be made public or not on upload (optional, defaultfalse)options.shouldCacheWhether a file should have cache headers applied (optional, defaultfalse)
Examples
const result = await delivery.uploadFile(
'./data/counties.json', // path to the file on local drive
'counties.json', // the key to give the file in S3, combined with `basePath`
{
isPublic: true,
}
);Returns Promise<UploadOutput>
uploadFiles
Upload a directory of files to S3.
Parameters
dirstring The directory to upload to S3options{prefix: string?, isPublic: boolean?, shouldCache: boolean?} (optional, default{})options.prefixThe prefix to add to the uploaded file's path (optional, default'')options.isPublicWhether all files uploaded should be made public (optional, defaultfalse)options.shouldCacheWhether all files uploaded should get cache headers (optional, defaultfalse)
Examples
const result = await delivery.uploadFiles(
'./dist/', // path to the directory on local drive to upload
{
isPublic: true,
prefix: 'output', // the key prefix to combine with `basePath`
}
);downloadFile
Downloads a file from S3 to the local disk.
Parameters
pathstring The path to the file to downloaddeststring Where to put the file on the local diskoptions{s3ETag: string?} (optional, default{})options.s3ETagIf the ETag from S3 is already known, it can be provided here
Examples
const result = await delivery.downloadFile(
'output/data.json', // key of file on S3 to download
'./downloaded/data.json', // where to download the file to the local drive
);downloadFiles
Downloads multiple files from a prefix on S3.
Parameters
prefixstring The prefix to the directory on S3 to download fromdirstring Where to put all the files on the local disk
Examples
const result = await delivery.downloadFiles(
'production', // the key of the directory on S3 to download from
'./downloaded/', // where to download the files to the local drive
);How outputs are structured
These represent the output objects from Delivery's commands.
DownloadOutput
What downloadFile and downloadFiles returns.
Key
The file's path on S3.
Type: string
isIdentical
Whether the file was identical on S3 or locally and was skipped.
Type: boolean
UploadOutput
What uploadFile and uploadFiles returns.
Key
The file's path on S3.
Type: string
isIdentical
Whether the file was identical on S3 or locally and was skipped.
Type: boolean
isPublic
This file was made public on upload.
Type: boolean
size
The size of the uploaded file in bytes.
Type: number
Delivery#upload
Type: UploadOutput
License
MIT
6 years ago