Reputation: 13
I'm using a function in a loop of files to validate each file, I need to go through the lines and match the version.
I've tried using an observable around my whole operation, unfortunately was not able to get it working the right way.
Any help is appreciated, thanks.
checkDumpVersion(file: File, vcVersion: string): boolean {
let reader = new FileReader();
reader.readAsText(file);
reader.onload = function(e) {
let firstLine = reader.result.toString().split(/\r\n|\n/).shift();
let tokens = firstLine.split(/(\s+)/).filter(e => e.trim().length > 0)
let version = tokens[tokens.indexOf('VERSION') + 1];
if (version !== VC_TO_DUMP[vcVersion]) {
console.log(STATUS['versionValidationError']);
// need to return false here.
}
}
return true;
}
Upvotes: 1
Views: 934
Reputation: 154
You can use a callback
function to return your response
checkDumpVersion(file: File, vcVersion: string, callback): boolean{
let reader = new FileReader(); reader.readAsText(file);
reader.onload = function(e){
let firstLine = reader.result.toString().split(/\r\n|\n/).shift();
let tokens = firstLine.split(/(\s+)/).filter( e => e.trim().length > 0)
let version = tokens[tokens.indexOf('VERSION') + 1];
if(version !== VC_TO_DUMP[vcVersion]){
console.log(STATUS['versionValidationError']);
// need to return false here.
callback(false)
}
}
return true;
}
checkDumpVersion(file, vcVersion, (data)=> {
console.log(data)
})
Upvotes: 2