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.
pull/854/head
no bk 4 years ago
parent 9f3be1eea6
commit c6ccd96407
  1. 5
      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 io.legado.app.utils.*
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
import java.nio.charset.Charset
class CacheViewModel(application: Application) : BaseViewModel(application) { class CacheViewModel(application: Application) : BaseViewModel(application) {
@ -67,7 +68,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
private suspend fun export(file: File, book: Book) { private suspend fun export(file: File, book: Book) {
val filename = "${book.name} by ${book.author}.txt" val filename = "${book.name} by ${book.author}.txt"
FileUtils.createFileIfNotExist(file, filename) FileUtils.createFileIfNotExist(file, filename)
.writeText(getAllContents(book)) .writeText(getAllContents(book), Charset.forName("GB18030"))
if (appCtx.getPrefBoolean(PreferKey.webDavCacheBackup, false)) { if (appCtx.getPrefBoolean(PreferKey.webDavCacheBackup, false)) {
BookWebDav.exportWebDav(file.absolutePath, filename) // 导出到webdav BookWebDav.exportWebDav(file.absolutePath, filename) // 导出到webdav
} }
@ -120,4 +121,4 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
} }
return srcList return srcList
} }
} }

Loading…
Cancel
Save