mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
Added asBytes method. Used InputStream.copyTo
This commit is contained in:
parent
e2c7125f6c
commit
a1b471d2ca
@ -13,16 +13,20 @@ fun PathedFile.asStream(
|
||||
fun PathedFile.asFile(
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
dest: File = File.createTempFile(this.fileUniqueId, this.filename),
|
||||
defaultBufferSize: Int = 1024,
|
||||
buffer: ByteArray = ByteArray(defaultBufferSize)
|
||||
defaultBufferSize: Int = 1024
|
||||
): File {
|
||||
this.asStream(telegramAPIUrlsKeeper).use { input ->
|
||||
FileOutputStream(dest).use { out ->
|
||||
var read: Int
|
||||
while (input.read(buffer, 0, defaultBufferSize).also { read = it } >= 0) {
|
||||
out.write(buffer, 0, read)
|
||||
}
|
||||
input.copyTo(out, defaultBufferSize)
|
||||
}
|
||||
}
|
||||
return dest
|
||||
}
|
||||
|
||||
fun PathedFile.asBytes(
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||
): ByteArray {
|
||||
return this.asStream(telegramAPIUrlsKeeper).use { input ->
|
||||
input.readBytes()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user