Probably not a good idea to store entire files as base64 data in variables and pass them through a bunch of functions - preferable to utilize an in-memory file system that only converts files to base64 when needed by the browser and to have it kept in one memory location in all other situations
Possible library option: https://github.com/streamich/memfs