Hello Team,
I have not found this kind of feature.
Please provide me any hint.
Thanks.
With respects, Eugene.
Kirill Gavrilov Sat, 02/12/2022 - 18:51
Low-level STL reader implementation RWStl_Reader works with std::istream. but higher level RWStl::ReadFile() works only with file paths. So either you have to (re)implement reading using RWStl_Reader or propose a patch for RWStl::ReadFile().
Is there a real need in reading STL from non-file origin in your case?
Hello Kirill,
Thank you for the answer.
I wanted to add STL reading to wasm functionality. This is a reason to read from stream.
Anyway it is not so critical for me now.
Emscripten provides an emulated file system which can be written directly from JavaScript (you would need adding `-s "EXPORTED_RUNTIME_METHODS=['FS']"` to linker flags) or from C++ level. It has drawbacks, but also useful side effects - emulated file system is not entirely mapped to WASM32 address space.
/**
* Fetch remote file from specified URL and upload it to emulated file system.
* @param[in] {string} theFileUrl URL to load
* @param[in] {string} theFilePath file path on emulated file system (or empty string to take name from URL)
* @param[in] {boolean} theToPreload decode image file using Emscripten plugins
* @return {Promise} evaluation result as promise returning TRUE or Error
*/
uploadUrl (theFileUrl, theFilePath, theToPreload)
{
let aPathSplit = theFileUrl.split ("/");
let aFileName = theFileUrl;
if (aPathSplit.length > 1)
{
aFileName = aPathSplit[aPathSplit.length - 1];
}
let aFilePath = theFilePath;
if (aFilePath === "")
{
aFilePath = aFileName;
}
const aCheckStatusFunc = function (theResponse)
{
if (!theResponse.ok) { throw new Error ("HTTP " + theResponse.status + " - " + theResponse.statusText + " (URL: '" + theFileUrl + "')"); }
return theResponse;
};
return new Promise ((theResolve, theReject) =>
{
fetch (theFileUrl)
.then (theResponse => aCheckStatusFunc (theResponse) && theResponse.arrayBuffer())
.then (theBuffer => {
let aDataArray = new Uint8Array (theBuffer);
this.terminalWriteLine ("uploading file '" + aFileName + "' of size " + aDataArray.length + " bytes to '" + aFilePath + "'...");
this.FS.writeFile (aFilePath, aDataArray);
if (theToPreload)
{
// decode image
this.FS.createPreloadedFile (!aFilePath.startsWith ("/") ? this.FS.cwd() : "/",
aFilePath,
aDataArray, true, true,
() => { theResolve (true); this.terminalPrintInputLine (""); },
() => { theReject (new Error ("Preload '" + aFilePath + "' failed")); },
true); // file is already created
}
else
{
this.terminalPrintInputLine ("");
theResolve (true);
}
})
.catch (theErr => {
theReject (theErr);
});
});
}
Sat, 02/12/2022 - 18:51
Low-level STL reader implementation RWStl_Reader works with std::istream. but higher level RWStl::ReadFile() works only with file paths. So either you have to (re)implement reading using RWStl_Reader or propose a patch for RWStl::ReadFile().
Is there a real need in reading STL from non-file origin in your case?
Tue, 02/15/2022 - 09:06
Hello Kirill,
Thank you for the answer.
I wanted to add STL reading to wasm functionality. This is a reason to read from stream.
Anyway it is not so critical for me now.
Thanks.
With respects, Eugene.
Tue, 02/15/2022 - 10:00
Emscripten provides an emulated file system which can be written directly from JavaScript (you would need adding `-s "EXPORTED_RUNTIME_METHODS=['FS']"` to linker flags) or from C++ level. It has drawbacks, but also useful side effects - emulated file system is not entirely mapped to WASM32 address space.