Javascript 使用Emscripten_wget或Emscripten_async_wget下载图像数据的Emscripten代码
我正在编写一个web应用程序,它必须执行一些c代码,所以我选择了emscripten。我需要的工作流如下所示: 从服务器下载图像并将其数据保存到文件系统中。 调用一些c函数来进行一些处理。 调用一些WebCryptoAPI函数来解密信息。 再次调用其他一些c函数进行处理。 在浏览器中显示结果。 由于它涉及大量Javascript和C混合,我不知道如何处理运行循环、异步等,因为我对emscripten完全是新手。 我的想法是使用emscripten_wget作为第一点,并使用MEMFS类型的FS保存它。我遇到的问题是同步加载图像 因此,在我的php文件中,我有以下内容:Javascript 使用Emscripten_wget或Emscripten_async_wget下载图像数据的Emscripten代码,javascript,c,emscripten,Javascript,C,Emscripten,我正在编写一个web应用程序,它必须执行一些c代码,所以我选择了emscripten。我需要的工作流如下所示: 从服务器下载图像并将其数据保存到文件系统中。 调用一些c函数来进行一些处理。 调用一些WebCryptoAPI函数来解密信息。 再次调用其他一些c函数进行处理。 在浏览器中显示结果。 由于它涉及大量Javascript和C混合,我不知道如何处理运行循环、异步等,因为我对emscripten完全是新手。 我的想法是使用emscripten_wget作为第一点,并使用MEMFS类型的FS保
<script type="text/javascript" src="a.out.js"></script>
<script>
P3Func = Module.cwrap('p3stuff', 'number', ['string', 'string']);
P3Func("<?php echo($imgurl); ?>", "<?php echo($wrappedkey); ?>");
</script>
int p3stuff(char *imgUrl, unsigned char *wrappedkey)
{
// create a directory "working" in the virtual file system and mount it to the current Posix file system.
EM_ASM(
FS.mkdir('/working');
FS.mount(MEMFS, {}, '/working');
);
char *path = "/working/myImage.jpg";
printf("Downloading...\n");
//Download image and save it to the File System
emscripten_wget(imgUrl, path);
printf("Download completed\n");
FILE *img;
img=fopen(path,"r");
if(img==NULL) {
printf("ERROR: Can't open file!\n");
exit (2);
}
}
实际上,我有一个奇怪的行为:wrappedkey参数长度为24个字符,我下载并正确读取图像,如果长度为22,我会出现无法打开文件错误,这对我来说毫无意义:
exit(2) called, but noExitRuntime, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)
然后:
still waiting on run dependencies:
a.out.js:139 dependency: cp /working/myImage.jpg
a.out.js:139 (end of list)
重复多次。是否使用-s ASYNCIFY=1构建?emscripten_wget需要它。当然,我正在使用ASYNCIFY=1构建