<commit_before>/**
 * Created by zsolt on 4/15/14.
 *
 * Represents a complex artifact in BLOB storage.
 */

define([], function () {

    var Artifact = function (name, blobClient, descriptor) {
        this.name = name;
        this.blobClient = blobClient;
        this.descriptor = descriptor || {}; // name and hash pairs
    };

    Artifact.prototype.addFile = function (name, content, callback) {
        var self = this;
        var filename = name.substring(name.lastIndexOf('/') + 1);
        this.blobClient.addObject(filename, content, function (err, hash) {
            if (err) {
                callback(err);
                return;
            }

            self.descriptor[name] = hash;
            callback(null, hash);
        });
    };

    Artifact.prototype.addFiles = function (o, callback) {
        throw new Error('not implemented yet.');
    };

    Artifact.prototype.addHash = function (name, hash) {
        this.descriptor[name] = hash;
    };

    Artifact.prototype.save = function (callback) {
        this.blobClient.addComplexObject(this.name, this.descriptor, callback);
    };


    return Artifact
});<commit_msg>Implement artifact.addFiles()<commit_after>/**
 * Created by zsolt on 4/15/14.
 *
 * Represents a complex artifact in BLOB storage.
 */

define([], function () {

    var Artifact = function (name, blobClient, descriptor) {
        this.name = name;
        this.blobClient = blobClient;
        this.descriptor = descriptor || {}; // name and hash pairs
    };

    Artifact.prototype.addFile = function (name, content, callback) {
        var self = this;
        var filename = name.substring(name.lastIndexOf('/') + 1);
        this.blobClient.addObject(filename, content, function (err, hash) {
            if (err) {
                callback(err);
                return;
            }

            self.descriptor[name] = hash;
            callback(null, hash);
        });
    };

    Artifact.prototype.addFiles = function (o, callback) {
        var self = this,
            fileNames = Object.keys(o),
            nbrOfFiles = fileNames.length,
            hashes = [],
            error = '',
            i;

        for (i = 0; i < fileNames.length; i += 1) {
            self.addFile(fileNames[i], o[fileNames[i]], function (err, hash) {
                error = err ? error + err : error;
                nbrOfFiles -= 1;
                hashes.push(hash);
                if (nbrOfFiles === 0) {
                    if (error) {
                        callback('Failed adding files: ' + error, hashes);
                        return;
                    }
                    callback(null, hashes);
                }
            });
        }
    };

    Artifact.prototype.addHash = function (name, hash) {
        this.descriptor[name] = hash;
    };

    Artifact.prototype.save = function (callback) {
        this.blobClient.addComplexObject(this.name, this.descriptor, callback);
    };


    return Artifact
});
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0053475935828877, 'mean_word_length': 1.7534498620055199, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3048750', 'n_tokens_mistral': 852, 'n_tokens_neox': 809, 'n_words': 197}