fix(core): update
This commit is contained in:
15
ts/index.ts
15
ts/index.ts
@ -1,13 +1,12 @@
|
||||
import * as plugins from './smartfile.plugins';
|
||||
import * as SmartfileFs from './smartfile.fs';
|
||||
import * as SmartfileInterpreter from './smartfile.interpreter';
|
||||
import * as SmartfileMemory from './smartfile.memory';
|
||||
import * as SmartfileRemote from './smartfile.remote';
|
||||
import * as fsMod from './smartfile.fs';
|
||||
import * as interpreterMod from './smartfile.interpreter';
|
||||
import * as memoryMod from './smartfile.memory';
|
||||
|
||||
export { Smartfile, ISmartfileConstructorOptions } from './smartfile.classes.smartfile';
|
||||
export { VirtualDirectory } from './smartfile.classes.virtualdirectory';
|
||||
|
||||
export let fs = SmartfileFs;
|
||||
export let interpreter = SmartfileInterpreter;
|
||||
export let memory = SmartfileMemory;
|
||||
export let remote = SmartfileRemote;
|
||||
|
||||
export let fs = fsMod;
|
||||
export let interpreter = interpreterMod;
|
||||
export let memory = memoryMod;
|
||||
|
@ -373,3 +373,15 @@ export const listFileTree = async (
|
||||
|
||||
return fileList;
|
||||
};
|
||||
|
||||
/**
|
||||
* checks wether a file is ready for processing
|
||||
*/
|
||||
export const waitForFileToBeReady = async (filePathArg: string) => {
|
||||
const limitedArray = new plugins.lik.LimitedArray<string>(3);
|
||||
if(!plugins.path.isAbsolute(filePathArg)) {
|
||||
filePathArg = plugins.path.resolve(filePathArg);
|
||||
};
|
||||
const stats = await plugins.fsExtra.stat(filePathArg);
|
||||
stats.size
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import * as path from 'path';
|
||||
export { fs, path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartfileInterfaces from '@pushrocks/smartfile-interfaces';
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartjson from '@pushrocks/smartjson';
|
||||
@ -13,7 +14,7 @@ import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { smartfileInterfaces, smarthash, smartjson, smartmime, smartpath, smartpromise, smartrequest };
|
||||
export { lik, smartfileInterfaces, smarthash, smartjson, smartmime, smartpath, smartpromise, smartrequest };
|
||||
|
||||
// third party scope
|
||||
import * as fsExtra from 'fs-extra';
|
||||
|
@ -1,51 +0,0 @@
|
||||
import plugins = require('./smartfile.plugins');
|
||||
import SmartfileInterpreter = require('./smartfile.interpreter');
|
||||
|
||||
/* export let toFs = function (from: string, toPath: string) {
|
||||
let done = plugins.q.defer()
|
||||
let stream = plugins.smartrequest(from).pipe(plugins.fsExtra.createWriteStream(toPath))
|
||||
stream.on('finish', function () {
|
||||
done.resolve(toPath)
|
||||
})
|
||||
return done.promise
|
||||
} */
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fromArg
|
||||
* @returns {any}
|
||||
*/
|
||||
export let toObject = (fromArg: string) => {
|
||||
const done = plugins.smartpromise.defer();
|
||||
plugins.smartrequest
|
||||
.request(fromArg, {
|
||||
method: 'get',
|
||||
})
|
||||
.then((res: any) => {
|
||||
if (res.statusCode === 200) {
|
||||
done.resolve(res.body);
|
||||
} else {
|
||||
console.log('could not get remote file from ' + fromArg);
|
||||
done.reject(new Error('could not get remote file from ' + fromArg));
|
||||
}
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fromArg
|
||||
* @returns {any}
|
||||
*/
|
||||
export let toString = (fromArg: string): Promise<string> => {
|
||||
const done = plugins.smartpromise.defer<string>();
|
||||
plugins.smartrequest.getBinary(fromArg).then((res: any) => {
|
||||
if (res.statusCode === 200) {
|
||||
const encoding = plugins.smartmime.getEncoding(fromArg);
|
||||
done.resolve(res.body.toString(encoding));
|
||||
} else {
|
||||
done.reject(new Error('could not get remote file from ' + fromArg));
|
||||
}
|
||||
});
|
||||
return done.promise;
|
||||
};
|
Reference in New Issue
Block a user