Address some build warnings

This commit is contained in:
arkon
2023-12-25 16:31:40 -05:00
parent 80d6d412f3
commit 2d7650537d
33 changed files with 102 additions and 144 deletions
@@ -20,17 +20,20 @@ class BackupDecoder(
* Decode a potentially-gzipped backup.
*/
fun decode(uri: Uri): Backup {
val backupStringSource = context.contentResolver.openInputStream(uri)!!.source().buffer()
return context.contentResolver.openInputStream(uri)!!.use { inputStream ->
val source = inputStream.source().buffer()
val peeked = backupStringSource.peek()
peeked.require(2)
val id1id2 = peeked.readShort()
val backupString = if (id1id2.toInt() == 0x1f8b) { // 0x1f8b is gzip magic bytes
backupStringSource.gzip().buffer()
} else {
backupStringSource
}.use { it.readByteArray() }
val peeked = source.peek().apply {
require(2)
}
val id1id2 = peeked.readShort()
val backupString = if (id1id2.toInt() == 0x1f8b) { // 0x1f8b is gzip magic bytes
source.gzip().buffer()
} else {
source
}.use { it.readByteArray() }
return parser.decodeFromByteArray(BackupSerializer, backupString)
parser.decodeFromByteArray(BackupSerializer, backupString)
}
}
}
@@ -68,7 +68,7 @@ class BackupCreator(
.forEach { it.delete() }
// Create new file to place backup
dir?.createFile(BackupCreator.getFilename())
dir?.createFile(getFilename())
} else {
UniFile.fromUri(context, uri)
}