Filter archive files as sequence

This commit is contained in:
arkon 2022-02-05 17:27:28 -05:00
parent 319e4360c8
commit aa5e428222
2 changed files with 6 additions and 9 deletions

View file

@ -42,18 +42,16 @@ class RarPageLoader(file: File) : PageLoader() {
* comparator.
*/
override fun getPages(): Observable<List<ReaderPage>> {
return archive.fileHeaders
return archive.fileHeaders.asSequence()
.filter { !it.isDirectory && ImageUtil.isImage(it.fileName) { archive.getInputStream(it) } }
.sortedWith { f1, f2 -> f1.fileName.compareToCaseInsensitiveNaturalOrder(f2.fileName) }
.mapIndexed { i, header ->
val streamFn = { getStream(header) }
ReaderPage(i).apply {
stream = streamFn
stream = { getStream(header) }
status = Page.READY
}
}
.let { Observable.just(it) }
.let { Observable.just(it.toList()) }
}
/**

View file

@ -37,17 +37,16 @@ class ZipPageLoader(file: File) : PageLoader() {
* comparator.
*/
override fun getPages(): Observable<List<ReaderPage>> {
return zip.entries().toList()
return zip.entries().asSequence()
.filter { !it.isDirectory && ImageUtil.isImage(it.name) { zip.getInputStream(it) } }
.sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) }
.mapIndexed { i, entry ->
val streamFn = { zip.getInputStream(entry) }
ReaderPage(i).apply {
stream = streamFn
stream = { zip.getInputStream(entry) }
status = Page.READY
}
}
.let { Observable.just(it) }
.let { Observable.just(it.toList()) }
}
/**