Created
December 19, 2018 19:33
-
-
Save darrenmothersele/5646afd7043d85bf1bb253d838c91e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is added globally by the zip.js library | |
| declare const zip: any; | |
| @Injectable() | |
| export class ZipService { | |
| constructor() { | |
| zip.workerScriptsPath = 'scripts/'; | |
| } | |
| getEntries(file): Observable<Array<ZipEntry>> { | |
| return new Observable(subscriber => { | |
| const reader = new zip.BlobReader(file); | |
| zip.createReader(reader, zipReader => { | |
| zipReader.getEntries(entries => { | |
| subscriber.next(entries); | |
| subscriber.complete(); | |
| }); | |
| }, message => { | |
| subscriber.error({ message }); | |
| }); | |
| }); | |
| } | |
| getData(entry: ZipEntry): ZipTask { | |
| const progress = new Subject<ZipTaskProgress>(); | |
| const data = new Observable<Blob>(subscriber => { | |
| const writer = new zip.BlobWriter(); | |
| // Using `as any` because we don't want to expose this | |
| // method in the interface | |
| (entry as any).getData(writer, blob => { | |
| subscriber.next(blob); | |
| subscriber.complete(); | |
| progress.next(null); | |
| }, (current, total) => { | |
| progress.next({ active: true, current, total }); | |
| }); | |
| }); | |
| return { progress, data }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment