From f02a9de4db3265d561105efcc89c2ad6915fd498 Mon Sep 17 00:00:00 2001 From: KaiserBh Date: Wed, 10 Jan 2024 19:59:01 +1100 Subject: [PATCH] fix: decoding and encoding. Signed-off-by: KaiserBh --- .../data/sync/service/GoogleDriveSyncService.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt index 5e6fba545..48f10d7d4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt @@ -137,7 +137,8 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync return withContext(Dispatchers.IO) { try { val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray())) - val syncData = json.decodeFromString(gzipInputStream.reader(Charsets.UTF_8).readText()) + val jsonString = gzipInputStream.bufferedReader(Charsets.UTF_8).use { it.readText() } + val syncData = json.decodeFromString(SyncData.serializer(), jsonString) logcat(LogPriority.DEBUG) { "JSON deserialized successfully" } syncData } catch (e: Exception) { @@ -157,10 +158,10 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync val byteArrayOutputStream = ByteArrayOutputStream() withContext(Dispatchers.IO) { + val jsonData = json.encodeToString(syncData) val gzipOutputStream = GZIPOutputStream(byteArrayOutputStream) - gzipOutputStream.writer(Charsets.UTF_8).use { writer -> - writer.write(json.encodeToString(syncData)) - } + gzipOutputStream.write(jsonData.toByteArray(Charsets.UTF_8)) + gzipOutputStream.close() logcat(LogPriority.DEBUG) { "JSON serialized successfully" } }