Skip to content

Instantly share code, notes, and snippets.

@merlosy
Last active July 15, 2019 22:52
Show Gist options
  • Save merlosy/75d40441ab9e96710508590f9506e076 to your computer and use it in GitHub Desktop.
Save merlosy/75d40441ab9e96710508590f9506e076 to your computer and use it in GitHub Desktop.
Blob to Json
blobToJson(blob: Blob): Observable<any> {
let loadend: Observable<any>;
if (blob.type === 'application/json') {
const reader = new FileReader();
loadend = fromEvent(reader, 'loadend').pipe(
map((read: any) => {
this.logger.debug('blobToJson:loadend *', JSON.parse(read.target.result));
return JSON.parse(read.target.result);
})
);
reader.readAsText(blob);
} else {
loadend = of({});
}
return loadend;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment