Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

transform_data

Marcel Kloubert edited this page Apr 12, 2017 · 18 revisions

Transform data

You can "transform" data (of a file) before it is send, or after it has been received from a source.

This is useful if you want to encrypt the data before it is send to a destination over a network connection and decrypt it after is has been received at the destination, e.g.

To do this, you have to create a JavaScript file that has the following skeleton:

// this function is used to RESTORE transformed
// data back into its origin format
// 
// if not defined, the 'transformData()' function is used
exports.restoreData = function(ctx) {
    var base64 = ctx.data.toString('ascii');

    return new Buffer(base64, 'base64');
}

// this function is used to TRANSFORM unhandled
// data into a new format
// 
// if not defined, the 'restoreData()' function is used
exports.transformData = function(ctx) {
    // return a Promise, if your
    // operation is done async
    return new Promise(function(resolve, reject) {
        try {
            // we simply encode the "original" data
            // to a Base64 string
            var base64 = ctx.data.toString('base64');

            // return encoded data
            resolve(new Buffer(base64, 'ascii'));
        }
        catch (e) {
            reject(e);
        }
    });
}

In plugins, like DropBox, HTTP or Remote, you can define now the path to your new script and give it additional data, if needed:

{
    "deploy": {
        "targets": [
            {
                "type": "http",
                "name": "My HTTP service",
                "description": "A HTTP service on a HTTP server, e.g.",

                "url": "https://host.example.com/webdav/?file=${VSDeploy-File}",

                "transformer": "/the/path/to/your/transformer_script.js",
                "transformerOptions": "Any data or object to submit to the functions"
            }
        ]
    }
}

ctx parameters

The ctx uses DataTransformerContext interface.

Clone this wiki locally