I'm having trouble reading trying to read a text file saved in the /Javascripts/ folder into javascript. Maybe it's my failure: I can make it work fine in the console, but if it's part of a toolbar button or menu item, it fails because util.readFileIntoStream() does not have permission.
I've tried making a trusted function for this, but if I copy util.readFileIntoStream() into a trustedPropagatorFunction the application crashes. Here's some partial code to reproduce.
// try to make a trust propagator function out of the readFileIntoStream function
var trustedReadFileFunction = app.trustPropagatorFunction( util.readFileIntoStream );
// make a trusted function to read the file
var trustedReadFile = app.trustedFunction( function(fileName) {
var filePath = app.getPath("user","javascript")+"/"+fileName;
app.beginPriv();
var theFile = trustedReadFileFunction( filePath ); // ***** CRASH ******
app.endPriv();
// do something with the file data
var hLines = util.stringFromStream(theFile).replaceAll(/[\n\r]+/ig,"\n").split("\n");
theFile = null;
return hLines;
});
trustedReadFile("MyFileName.txt");
// try to make a trust propagator function out of the readFileIntoStream function
var trustedReadFileFunction = app.trustPropagatorFunction( file => util.readFileIntoStream(file) );
// make a trusted function to read the file
var trustedReadFile = app.trustedFunction( function(fileName) {
var filePath = app.getPath("user","javascript")+"/"+fileName;
app.beginPriv();
var theFile = trustedReadFileFunction( filePath ); // ***** CRASH ******
app.endPriv();
// do something with the file data
var hLines = util.stringFromStream(theFile).replaceAll(/[\n\r]+/ig,"\n").split("\n");
theFile = null;
return hLines;
});
trustedReadFile("MyFileName.txt");
To be sure, are you running the current latest release (9.5.368.0)? Older versions of the software did have more restrictions on security methods that could be used, and that may be part of the issue here. If you are updated and are still seeing this issue, please let me know and I will wave Roman over for his help again
Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Hi Mathew,
Yes, our support for trusted functions is incomplete at the moment. We are going improve this in the next major release of the Editor. It is expected within the next month.