Skip to content

Commit

Permalink
Fix PsPDFKit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
qnga committed Nov 20, 2023
1 parent 69d9dd9 commit e720ebc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,18 @@ public class PsPdfKitDocumentFactory(context: Context) : PdfDocumentFactory<PsPd
override val documentType: KClass<PsPdfKitDocument> = PsPdfKitDocument::class

override suspend fun open(resource: Resource, password: String?): ResourceTry<PsPdfKitDocument> =
open(context, DocumentSource(ResourceDataProvider(resource), password))

// FIXME : error handling is too rough
private suspend fun open(context: Context, documentSource: DocumentSource): ResourceTry<PsPdfKitDocument> =
withContext(Dispatchers.IO) {
val dataProvider = ResourceDataProvider(resource)
val documentSource = DocumentSource(dataProvider)
try {
Try.success(
PsPdfKitDocument(PdfDocumentLoader.openDocument(context, documentSource))
)
val innerDocument = PdfDocumentLoader.openDocument(context, documentSource)
Try.success(PsPdfKitDocument(innerDocument))
} catch (e: InvalidPasswordException) {
Try.failure(ReadError.Decoding(ThrowableError(e)))
} catch (e: InvalidSignatureException) {
Try.failure(ReadError.Decoding(ThrowableError(e)))
} catch (e: IOException) {
Try.failure(ReadError.Other(e))
Try.failure(dataProvider.error!!)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ public class BlobInputStream(
*/
private var mark: Long = range?.start ?: 0

private var error: ReadError? = null

internal fun consumeError(): ReadError? {
val errorNow = error
error = null
return errorNow
}

override fun available(): Int {
checkNotClosed()
return (end - position).toInt()
Expand Down Expand Up @@ -146,7 +138,6 @@ public class BlobInputStream(
value
}
is Try.Failure -> {
error = value
throw wrapError(value)
}
}
Expand Down

0 comments on commit e720ebc

Please sign in to comment.