fix(core): update

This commit is contained in:
2020-03-04 16:31:13 +00:00
parent f86f053bd5
commit b4add67f37
5 changed files with 192 additions and 109 deletions

View File

@ -192,14 +192,17 @@ export const toObjectSync = (filePathArg, fileTypeArg?) => {
/**
* reads a file content to a String
* @param filePath
* @returns {string|Buffer|any}
*/
export const toStringSync = (filePath: string): string => {
const fileString: string = plugins.fsExtra.readFileSync(filePath, 'utf8');
const encoding = plugins.smartmime.getEncoding(filePath);
const fileString: string = plugins.fsExtra.readFileSync(filePath, encoding);
return fileString;
};
export const toBufferSync = (filePath: string): Buffer => {
return plugins.fsExtra.readFileSync(filePath);
}
export const fileTreeToHash = async (dirPathArg: string, miniMatchFilter: string) => {
const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter);
let combinedString = '';

View File

@ -6,11 +6,12 @@ export { fs, path };
// @pushrocks scope
import * as smarthash from '@pushrocks/smarthash';
import * as smartmime from '@pushrocks/smartmime';
import * as smartpath from '@pushrocks/smartpath';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export { smarthash, smartpath, smartpromise, smartrequest };
export { smarthash, smartmime, smartpath, smartpromise, smartrequest };
// third party scope
import * as fsExtra from 'fs-extra';

View File

@ -15,8 +15,8 @@ import SmartfileInterpreter = require('./smartfile.interpreter');
* @param fromArg
* @returns {any}
*/
export let toObject = function(fromArg: string) {
let done = plugins.smartpromise.defer();
export let toObject = (fromArg: string) => {
const done = plugins.smartpromise.defer();
plugins.smartrequest
.request(fromArg, {
method: 'get'
@ -37,11 +37,12 @@ export let toObject = function(fromArg: string) {
* @param fromArg
* @returns {any}
*/
export let toString = (fromArg: string) => {
let done = plugins.smartpromise.defer();
export let toString = (fromArg: string): Promise<string> => {
const done = plugins.smartpromise.defer<string>();
plugins.smartrequest.getBinary(fromArg).then((res: any) => {
if (res.statusCode === 200) {
done.resolve(res.body);
const encoding = plugins.smartmime.getEncoding(fromArg);
done.resolve(res.body.toString(encoding));
} else {
done.reject(new Error('could not get remote file from ' + fromArg));
}