breautek commented on issue #364: Large file save freeze app for seconds
URL: 
https://github.com/apache/cordova-plugin-file/issues/364#issuecomment-589915035
 
 
   The line that blocks the UI thread for a significant amount of time here I 
found to be:
   
   
https://github.com/apache/cordova-android/blob/c35a990c09f1ab278873754eb7f81e52250893a3/cordova-js-src/exec.js#L87
   
   `args[i] = base64.fromArrayBuffer(args[i]);`
   
   When blobs are used, it reads the blob as an arraybuffer. Then it converts 
the array buffer to a base64 encoded string. I assume it does this because the 
[JavasciptInterface](https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String))
 I believe can only accept strings. Unfortunately, I don't think there is any 
way around that, based on some brief googling around.
   
   This is a weak workaround since this plugin is deprecated, you can try using 
the [file transfer](https://github.com/apache/cordova-plugin-file-transfer) 
plugin which allows you to download a file and save it to the file system 
completely on the native side. I do still use the file transfer plugin myself 
in my own apps and it still works, but it is a plugin that cordova doesn't 
provide updates or support for.
   
   Possible ideas for solutions:
   
   Cordova doesn't support web workers, but I think this would be a good case 
where web workers would be beneficial, to at least move the bridge execution 
calls off the UI thread. It won't improve performance, but at least it will 
make `exec` non-blocking.
   
   Another idea is to bring the concept of file transfers into the `file` 
plugin downloading and saving to the filesystem can be handled completely on 
the native side to avoid dealing with binary data in the javascript environment.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to