From c6ccd9640703183c13eedc2ef84ddd7b3fa6c8f9 Mon Sep 17 00:00:00 2001 From: no bk Date: Thu, 18 Feb 2021 23:33:26 +0800 Subject: [PATCH] export .txt file using Codeset GB18030 to save storage UTF-8 and GB18030 are two dialects of Uncode. All code points are completely equivalent. However, if the document is completely Chinese, using GB18030 can save 1/3 of the storage space, a 3MB UTF-8 encoded .txt Chinese file , It only needs 2MB storage space to convert to GB18030 encoding. --- .../main/java/io/legado/app/ui/book/cache/CacheViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 9737b618a..8b5388fb7 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -15,6 +15,7 @@ import io.legado.app.help.storage.BookWebDav import io.legado.app.utils.* import splitties.init.appCtx import java.io.File +import java.nio.charset.Charset class CacheViewModel(application: Application) : BaseViewModel(application) { @@ -67,7 +68,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { private suspend fun export(file: File, book: Book) { val filename = "${book.name} by ${book.author}.txt" FileUtils.createFileIfNotExist(file, filename) - .writeText(getAllContents(book)) + .writeText(getAllContents(book), Charset.forName("GB18030")) if (appCtx.getPrefBoolean(PreferKey.webDavCacheBackup, false)) { BookWebDav.exportWebDav(file.absolutePath, filename) // 导出到webdav } @@ -120,4 +121,4 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } return srcList } -} \ No newline at end of file +}