mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 03:45:33 -04:00
Simplified the creation of splitted zim file.
This commit is contained in:
parent
326b3901c4
commit
c0912dee89
@ -117,30 +117,23 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() {
|
|||||||
var currentPartSize: Long = 0
|
var currentPartSize: Long = 0
|
||||||
val buffer = ByteArray(1024)
|
val buffer = ByteArray(1024)
|
||||||
var length: Int
|
var length: Int
|
||||||
var outputStream: OutputStream
|
var outputStream: OutputStream? = null
|
||||||
|
|
||||||
while (inputStream.read(buffer).also { length = it } > 0) {
|
while (inputStream.read(buffer).also { length = it } > 0) {
|
||||||
// If current part size exceeds or equals partSize, move to the next part
|
|
||||||
if (currentPartSize >= partSize || bytesRead == 0L) {
|
if (currentPartSize >= partSize || bytesRead == 0L) {
|
||||||
outputStream = FileOutputStream(
|
outputStream?.close() // Close the previous outputStream if any open.
|
||||||
File(storageDir, "testzim.zima${('a' + partNumber - 1).toChar()}")
|
val partFile = File(storageDir, "testzim.zima${('a' + partNumber - 1).toChar()}")
|
||||||
)
|
outputStream = FileOutputStream(partFile)
|
||||||
partNumber++
|
partNumber++
|
||||||
currentPartSize = 0
|
currentPartSize = 0
|
||||||
} else {
|
|
||||||
outputStream = FileOutputStream(
|
|
||||||
File(storageDir, "testzim.zima${('a' + partNumber - 2).toChar()}"),
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputStream.use {
|
outputStream?.write(buffer, 0, length)
|
||||||
it.write(buffer, 0, length)
|
|
||||||
}
|
|
||||||
|
|
||||||
bytesRead += length
|
bytesRead += length
|
||||||
currentPartSize += length
|
currentPartSize += length
|
||||||
}
|
}
|
||||||
|
outputStream?.close()
|
||||||
}
|
}
|
||||||
val splittedZimFile = File(storageDir, "testzim.zimaa")
|
val splittedZimFile = File(storageDir, "testzim.zimaa")
|
||||||
return if (splittedZimFile.exists()) splittedZimFile else null
|
return if (splittedZimFile.exists()) splittedZimFile else null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user