Muhammed Emir
Muhammed Emir

Reputation: 15

Flutter encrypt large files

I want to change the file's byte for encryption, but when i use readAsBytes() method for large file, i get out of memory error. So is there any way to encrypt large file with less memory consumption. Thank you

Upvotes: 0

Views: 786

Answers (1)

nvoigt
nvoigt

Reputation: 77304

Generally speaking, you need a temporary buffer to hold your data. If your RAM is not large enough (very likely on mobile devices) it has to be the disk.

So create a second file, and read the first file in batches of bytes that are small enough your memory will be able to handle it. Your encryption method should be able to handle this, as it's a very common occurrence. Write the resulting batches of encrypted content to the second file. Once you are done, delete/overwrite the original.

Upvotes: 1

Related Questions