Closed JavierAroche closed 6 years ago
Maybe we could optionaly save very big strings (XMP, RAW) as a file to file system and make path reference instead value itself? What about temp folder used by Photoshop.
If we're going to save to the user's file system, we should save the entire descriptor output to an external file. Maybe we have a flag like this?
var descFlags = {
reference : false,
extended : false,
maxStringLimit : 5000,
saveToFile : '~/Desktop/output.json'
};
If the user sets a maxStringLimit, then it'll use that for any string (RAW, XMP, etc), otherwise it defaults to 10,000 max.
If the user sets the saveToFile flag, then it will only save to file, without a max string limit. The only downside is that this method will not return anything in JSX, since it could crash. Thoughts?
I think there should be some faster way how to save data to file. I will try to do some measurements what is fastest way for saving data. Maybe is problem stroting long text in variable? Maybe variable should have always only part of string? Like a buffer?
Is there any chance run saving in separated thread? Can we use setTimeout?
I am also not sure if all raw data should be in one file. Maybe we could save it into separated files in one folder?
I can confirm that. If you save Raw data into file without writing it in variable then it's pretty fast.
var count = 0;
function saveTxt(txt)
{
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var Ext = decodeURI(app.activeDocument.name).replace(/^.*\./,'');
if (Ext.toLowerCase() != 'psd')
return;
var Path = app.activeDocument.path;
var saveFile = File(Path + "/" + "descriptor-data" + count+".bin");
count++;
if(saveFile.exists)
saveFile.remove();
saveFile.encoding = "UTF8";
saveFile.open("e", "TEXT", "????");
saveFile.writeln(txt);
saveFile.close();
}
case 'DescValueType.RAWTYPE':
if(theDesc.getData( position ).length > this.descParams.maxRawLimit){
saveTxt(theDesc.getData( position ));
}
return theDesc.getData( position ).substring( 0, this.descParams.maxRawLimit );
break;
It seems that script doesn't has problem store 1,5MB text in variable. The problem is if you want save it as JSON file. Probably JSON processing takes most time. So if JSON has to process a few milion character less then it runs faster :-)
Saving files itself is not problem.
This was implemented in https://github.com/JavierAroche/descriptor-info/pull/12
Limit the max number of characters in the XMPMetadataAsUTF8 string. This is especially problematic if the comp has 10000+ lines of metadata.