Here are some of my thoughts on bypassing the 4k limit of file operations:
- Write big data into one file
The above is the correct way to write large files:
:execute script file=filename
where script must print or return data, which “execute” will write to file.
I’ll add a few of my thoughts to this:
a) If we want to write data from string variable - it must be remembered that a variable can contain data no larger than 64kb (variable limit, but at least this limit is larger)
b) If we use script=“:put "$data"” in “ececute” - content must be very simple text string, without special chars, control chars, and other chars which requires to escaped.
The way to output original data with any chars without damage - pass variable into “execute” scope through global environment:
:global tempData $data;
:execute script={ :global tempData; :put $tempData; :set tempData; } file=filename
c) This “execute” method also has an unrecoverable drawback.
Whatever data is written to the file - a newline “\r\n” will always be added at the end of the file.
If we use “return” instead “put” in “execute” script - also “newline” added, but “\n”, and in doing so, we lose the ability to remove the global variable at the end of this script. Based on this, it is more preferable to use “put”.
2. Read big data from one file to variable
May be use:
:local fileContent ( [ /tool fetch url=( "ftp://127.0.0.1/" . $fileName ) user="login" password="password" port=21 mode=ftp as-value output=user ]->"data" );
via local FTP
But this method involves additional steps and checks.
a) Need save ftp-server “disabled” state and current port
b) Enable ftp-server if than disabled
c) Script need contain plain-text login and password of system user with full-rights. Another way - create temp user in script
d) Read file into variable by “tool fetch” with current port
e) Remove temp user if created
f) Disable the server if it was disabled before this operation (use saved state)
Also remeber - we have a 64kb variable limit.
But if file more than 64kb - it is possible to read at least the first 64kb by this method.