In copyFileToLocalStorage(), streams are not closed safely and the output stream is closed twice.
- Double-close:
outputStream is closed inside outputStream.use { ... }, then outputStream.close() is called again. The second close is redundant and can cause issues.
- Leak on error:
inputStream is not used inside a use block. If inputStream?.copyTo(fileOut) throws, the input stream is never closed.
Suggested fix: Use inputStream?.use { it.copyTo(fileOut) } so the input stream is always closed, and remove the explicit inputStream?.close() and outputStream.close() calls so only use is responsible for closing.
In
copyFileToLocalStorage(), streams are not closed safely and the output stream is closed twice.outputStreamis closed insideoutputStream.use { ... }, thenoutputStream.close()is called again. The second close is redundant and can cause issues.inputStreamis not used inside auseblock. IfinputStream?.copyTo(fileOut)throws, the input stream is never closed.Suggested fix: Use
inputStream?.use { it.copyTo(fileOut) }so the input stream is always closed, and remove the explicitinputStream?.close()andoutputStream.close()calls so onlyuseis responsible for closing.