-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Intercept downloads to transcode/decrypt payload #136
Comments
I love this idea of being able to inspect and transform the stream, I'll add it :) It could become quite noisy on the bridge though, so I hope that doesn't thwart this plan. As for your specific use-case and for my perspective: it would be more efficient to use an encryption library that decrypts data outside the JavaScript thread, no? Something like the snippet below: const request0 = ...
const fetchedResult = await BlobCourier.fetchBlob(request0);
const { absoluteFilePath } = fetchedResult.data;
await NativeEncryptionLibrary.decrypt(absoluteFilePath, Method.AES); Oddly I didn't find any library that supports this after a little googling, which I figure is your reason for processing the stream in the JavaScript thread? |
The stream would be processed natively, not in JS using react-native-simple-crypto but I'd like to not have an XX MiB encrypted file on disc temporarily when I could just decrypt the downstream and only write the decrytped bytes to disc. Another way would be to maybe have import crypt from "react-native-blob-courier-crypt"
await BlobCourier
.addNativeInterceptor(crypt, { key: aesKey, iv: aesIv })
.fetch("https://example.org/encrypted.enc") Then blob-courier could natively call the native plugin? And Does this sound like a plan? |
Sounds very reasonable :) The possible problem with both suggestions is congestion of the bridge; maybe it isn't even a problem, but we'll only find out when we test it. There should be a more efficient way than this, though:
This is true for both the first suggestion and the plugin solution, or maybe I don't follow correctly? I concocted another solution: send each received package not over the JS bridge, but over an in-process (Native) bus. That way you can create a simple wrapper around a library like
Does this make sense? What it boils down to is that separate libraries and plugins can only work together through messaging and my suggestion avoids using the JS bridge for that, which I expect to result in better performance and less memory consumption. NB. I think I will release both solutions as separate features; I'll start with your original plan of |
@edeckers I would opt for the high performance in process solution to start with. However I would give the plugin only transform capability an no file writing burdens.
|
Coming back to this... how about using the new native JNI of react like react-native-vision-camera? Then no bridge is involved, if I understood that correctly? |
Hi @pke , apologies for the late reply I was vacationing. As for your question, I think you meant to refer to the new JSI architecture / Turbomodules or am I wrong? I have been working on migrating BlobCourier to it #213. There's two things holding it up for now:
That being said, I don't think react-native-vision-camera uses the TurboModules-architecture, but they do use JNI as you mentioned correctly. Although they seem to achieve it through this method: https://thebhwgroup.com/blog/react-native-jni. That fixes the problem only for specific plugins you'd write for BlobCourier though, you wouldn't be able to hook-up react-native-simple-crypto as-is. The way I understand TurboModules at this time - as I mentioned above, I'm not 100% confident yet - I think you're right and they should solve our problem indeed. But only if both
|
Currently I am downloading encrypted payload and its stored on storage as a file. To display the data in the app
After the download I have to read the whole file that was just written to storage back into memory (in chunks or as a whole), decrypt it, save it back to storage and removing the encrypted version of the file.
I wonder now if the library could allow the user to supply a file writing interceptor that this lib delegates the file writing to like this:
Some starting point maybe?
https://medium.com/swlh/okhttp-interceptors-with-retrofit-2dcc322cc3f3
It would be crucial to operate on streams rather than having the whole response in memory.
The text was updated successfully, but these errors were encountered: