66 lines
4.4 KiB
JavaScript
66 lines
4.4 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
const plugins = require("./smartfile.plugins");
|
|
const SmartfileInterpreter = require("./smartfile.interpreter");
|
|
exports.toFs = function (from, toPath) {
|
|
var done = plugins.Q.defer();
|
|
var stream = plugins.request(from).pipe(plugins.fs.createWriteStream(toPath));
|
|
stream.on('finish', function () {
|
|
done.resolve(toPath);
|
|
});
|
|
return done.promise;
|
|
};
|
|
/**
|
|
*
|
|
* @param filePathArg
|
|
* @returns {*}
|
|
*/
|
|
exports.toGulpStreamSync = function (filePathArg, baseArg) {
|
|
let stream = plugins.g.remoteSrc(filePathArg, {
|
|
base: baseArg
|
|
});
|
|
return stream;
|
|
};
|
|
/**
|
|
*
|
|
* @param fromArg
|
|
* @returns {any}
|
|
*/
|
|
exports.toObject = function (fromArg) {
|
|
let done = plugins.Q.defer();
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
|
let returnObject;
|
|
if (!error && response.statusCode == 200) {
|
|
returnObject = SmartfileInterpreter.objectFile(bodyString, SmartfileInterpreter.filetype(fromArg));
|
|
done.resolve(returnObject);
|
|
}
|
|
else {
|
|
console.log('could not get remote file from ' + fromArg);
|
|
returnObject = undefined;
|
|
done.reject(returnObject);
|
|
}
|
|
;
|
|
});
|
|
return done.promise;
|
|
};
|
|
/**
|
|
*
|
|
* @param fromArg
|
|
* @returns {any}
|
|
*/
|
|
exports.toString = (fromArg) => {
|
|
let done = plugins.Q.defer();
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
|
if (!error && response.statusCode == 200) {
|
|
done.resolve(bodyString);
|
|
}
|
|
else {
|
|
plugins.beautylog.error('could not get remote file from ' + fromArg);
|
|
bodyString = undefined;
|
|
done.reject(bodyString);
|
|
}
|
|
;
|
|
});
|
|
return done.promise;
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyI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