Skip to main content

Uploading

One of the main operations for rac-delta is uploading new versions of your builds or directories, and apply only chunk changed or removing obsolete chunks from remote storage.

You can use rac-delta to update a build or to upload a completely new build to your storage.

Upload pipeline

For this, rac-delta SDK provides an upload pipeline which already implements all steps to automatically upload new builds to your storage.

Basic pipeline usage:


const remoteIndexToUse = undefined;

await racDeltaClient.pipelines.upload.execute('path/to/build', remoteIndexToUse, {
requireRemoteIndex: false,
force: false,
ignorePatterns: undefined,
onStateChange: (state) => {
console.log(state);
},
onProgress: (type, progress, speed) => {
console.log(type, progress.toFixed(1), speed?.toFixed(1));
},
});

Parameters:

NameTypeDescription
pathstringThe path to your local build that will be uploaded (relative or absolute path)
remote rd-indexRDIndexThe rd-index.json as RDIndex object that will be used as remote index, if none provided, the pipeline will try to download it from your storage
upload optionsUploadOptions
Parameter Type Description
requireRemoteIndex boolean If false, won't throw error if no remote index found and will upload everything
force boolean If true, will upload everything except ignore patterns
ignorePatterns string[] files or directories to ignore at the generation of the rd-index.json. Example: '*.zip' or 'dir/**'
onStateChange(state: UploadState) => void Callback that will notify when the pipeline changes its state. Available states are: uploading, comparing, cleaning, scanning and finalizing
onProgress(type: "upload" | "deleting", progress: number, speed?: numberCallback that will notify the progress of the upload operations. It will notify uploading progress and network speed, and deleting remote chunks progress

This will automatically generate your local rd-index.json, get remote rd-index.json if none was provided, compare both indexes, generate a Delta Plan and upload and cleaning the new chunks to your storage configured in the rac-delta client.

Pipeline helpers

In order to achieve the correct upload of the directory using rac-delta, the upload pipeline uses internal methods that uses rac-delta services for uploading, index comparison, deletion of obsolete chunks, etc...

If you don't want to use the default execute method, you can create your own pipeline using those helpers and services.

Example usage of pipeline helpers:


const racDeltaClient = await RacDeltaClient.create({
chunkSize: 1024 * 1024,
maxConcurrency: 6,
storage: {
type: 'ssh',
host: 'localhost',
pathPrefix: '/root/upload',
port: 2222,
credentials: {
username: 'root',
password: 'password',
},
},
});

const remoteIndex = fetch('my/api/or/my/storage/rd-index.json');

// Generate local rd-index.json (you could use racDeltaClient.delta.createIndexFromDirectory too)
const localIndex = await racDeltaClient.pipelines.upload.scanDirectory('my/build');

// Generate a deltaPlan comparing both indexes
const deltaPlan = await racDeltaClient.delta.compareForUpload(localIndex, remoteIndex);

// Upload new chunks (uses maxConcurrency from client)
await racDeltaClient.pipelines.upload.uploadMissingChunks(deltaPlan, 'my/build', false);

//... Delete obsolete chunks, upload new rd-index... etc

For a full list of Upload Pipeline helpers see: pipelines Also see DeltaPlan