Open file descriptor in "wt" mode for overwriting

This commit is contained in:
FooIbar committed 2024-04-05 00:04:02 +08:00
1 parent 11429ef7fe
commit 29e4e77c44
4 files changed
+3 -5

No files matched your search

@@ -99,7 +99,6 @@ fun ComicInfo.toSimpleTags() = listOfNotNull(
fun ComicInfo.write(file: UniFile) {
file.openOutputStream().use {
it.channel.truncate(0)
OutputStreamWriter(it, Charsets.UTF_8).use { writer ->
xmlStreaming.newGenericWriter(writer).use { xmlWriter ->
xml.encodeToWriter(xmlWriter, ComicInfo.serializer(), this)
@@ -191,8 +191,7 @@ class SpiderDen(val info: GalleryInfo) {
val extension = MimeTypeMap.getFileExtensionFromUrl(url).ifEmpty { "jpg" }
return saveResponseMeta(index, extension) { outFile ->
outFile.openOutputStream().use {
val chan = it.channel.apply { truncate(0) }
response.bodyAsChannel().copyTo(chan)
response.bodyAsChannel().copyTo(it.channel)
}
}
}
@@ -25,5 +25,5 @@ infix fun ParcelFileDescriptor.sendTo(fd: ParcelFileDescriptor) {
}
infix fun UniFile.sendTo(file: UniFile) = openFileDescriptor("r").use { src ->
file.openFileDescriptor("w").use { dst -> src sendTo dst }
file.openFileDescriptor("wt").use { dst -> src sendTo dst }
}
@@ -22,7 +22,7 @@ fun UniFile.openInputStream(): FileInputStream {
* Use Native IO/NIO directly if possible, unless you need process file content on JVM!
*/
fun UniFile.openOutputStream(): FileOutputStream {
return AutoCloseOutputStream(openFileDescriptor("w"))
return AutoCloseOutputStream(openFileDescriptor("wt"))
}
fun UniFile.sha1() = openFileDescriptor("r").use { sha1(it.fd) }