Skip to content

Very low copy speed #401

@vasiledoe

Description

@vasiledoe

Problem

I need to copy files from USB to device storage, I do it like so:

@Throws(IOException::class)
fun UsbFile.copyTo(outFile: File) {
    var inStream: InputStream? = null
    try {
        inStream = BufferedInputStream(UsbFileInputStream(this))
        val outStream: OutputStream = FileOutputStream(outFile)
        outStream.use {
            inStream.copyTo(it)
            it.close()
        }
    } catch (e: Exception) {
        e.printStackTrace()
    } finally {
        inStream?.close()
    }
}

this kotlin copyTo() method uses default buffer soze:
public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024 (8KB)

This operation takes a lot, especially for big video files. If we increase buffer size like DEFAULT_BUFFER_SIZE * 8 (64KB) then speed will be increased too but this doesn't guarantee that file will be copied successfully. This will work only if Allocation unit size is set >= with this buffer size. There is no way to determine this value from the lib API. Actually we have chunkSize defined in me.jahnen.libaums.core.fs.FileSystem but it always retutns 512

This is where we can change USB Allocation unit size
image

Expected behavior

Maybe there is a better/faster way to copy files from USB to internal memory.
Maybe there is a way to determine the right value for USB Allocation unit size so we can use it in order to copy faster.

** @magnusja your feedback is appreciated

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions