<commit_before>// Dependencies
var jipics  = "http://jipics.net/"
  , Request = require("request")
  , fs      = require("fs")
  ;

/**
 * upload
 *
 * @name upload
 * @function
 * @param {Object} options a string representing the image path or an
 *  object contanining the following fields:
 *   - path: the path to the image
 *   - deleteAfterUpload: if true, the image will be deleted after a sucessful upload
 * @param {Function} callback The callback function that will be called after upload is done.
 * @return {Object} The post request that is made
 */
exports.upload = function (options, callback) {

    // get the image from the request
    if (typeof options === "string") {
        options = {
            path: options
        }
    }

    // force options to be an object
    options = Object(options);

    // validate options
    if (!options.path && !options.stream) {
        return callback ("A path or a stream to the image must be provided.");
    }

    var stream = options.path ? fs.createReadStream(options.path) : options.stream;

    // upload the image to jipics.net
    return Request.post(jipics, function (err, res) {

        // handle error
        if (err) { return callback(err); }

        // parse body
        try {
            res.body = JSON.parse(res.body);
        } catch (e) {
            return callback(res.body);
        }

        // delete image
        if (options.deleteAfterUpload && options.path) {
            fs.unlink(options.path);
        }

        // callback
        callback (null, res.body);

    // create the read stream from image file
    }).form().append("image", stream);
};<commit_msg>Comments<commit_after>// Dependencies
var Request = require("request");
var Fs      = require("fs");

// Jipics usr
const JIPICS_URL  = "http://jipics.net/";

// Constructor
var Jipics = module.exports = {};

/**
 * upload
 *
 * @name upload
 * @function
 * @param {Object} options a string representing the image path or an
 *  object contanining the following fields:
 *   - path: the path to the image
 *   - deleteAfterUpload: if true, the image will be deleted after a sucessful upload
 * @param {Function} callback The callback function that will be called after upload is done.
 * @return {Object} The post request that is made
 */
Jipics.upload = function (options, callback) {

    // Get the image from the request
    if (typeof options === "string") {
        options = {
            path: options
        }
    }

    // Force options to be an object
    options = Object(options);

    // Validate options
    if (!options.path && !options.stream) {
        return callback ("A path or a stream to the image must be provided.");
    }

    // Create stream from hard disk or remote
    var stream = options.path ? fs.createReadStream(options.path) : options.stream;

    // Upload the image to jipics.net
    return Request.post(JIPICS_URL, function (err, res) {
        if (err) { return callback(err); }

        // parse body
        try {
            res.body = JSON.parse(res.body);
        } catch (e) {
            return callback(res.body);
        }

        // delete image
        if (options.deleteAfterUpload && options.path) {
            fs.unlink(options.path);
        }

        // callback
        callback (null, res.body);
    }).form().append("image", stream);
};
{'fraction_non_alphanumeric': 0.11561382598331346, 'fraction_numerical': 0.0, 'mean_word_length': 2.2560620756547043, 'pattern_counts': {'":': 0, '<': 3, '<?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': '28441', 'n_tokens_mistral': 947, 'n_tokens_neox': 926, 'n_words': 328}