Page 1 of 1

Readfile()/Writefile() start/end parameters.

Posted: 14 May 2022 15:50
by eil
Readfile() has [start] parameter, which appeared due to explained limitation: This command will not read more than 100 MB at a time. To read larger files use the "start" parameter and do it portion by portion. Except limitation reasons this parameter is useful in other situations, when one needs to exactly read not from the start. But lack of [end] parameters kinda hurts, as file must be read till the end and then manually cut in variable.
So, Reading "from" positions is good, but reading "till" - makes it better.

Another concern is Writefile() command, which can only save whole file. I'm not sure if XY can do the desired "insert write", i just guess, as reading raw is fine, why not writing.
Basically, writing inside already existing file, rewriting from [start] to [end] positions, would be useful to have.(yeap, hex editing goes scripting)

Re: Readfile()/Writefile() start/end parameters.

Posted: 30 Aug 2022 21:13
by eil
Scripting got lots of updates recently, maybe it's time for this?..

Re: Readfile()/Writefile() start/end parameters.

Posted: 30 Aug 2022 21:40
by klownboy
In the case of SC readfile, you can specify in the "numbytes" parameter how many bytes to read. Isn't that essentially the same as an "end" parameter with a different name?

Code: Select all

 From Help > Scripting Commands:
 numbytes:
 empty: read whole file 

 else: number of bytes to read; if longer than file size then the number is silently set to file size;
if <= 0 the function returns an empty string (and does not even try to read the file) 

Re: Readfile()/Writefile() start/end parameters.

Posted: 31 Aug 2022 09:42
by eil
klownboy wrote: 30 Aug 2022 21:40 In the case of SC readfile, you can specify in the "numbytes" parameter how many bytes to read. Isn't that essentially the same as an "end" parameter with a different name?
Well, my bad in this case, but as you see "different name" may not allow to actually notice there is kinda an option. Yet, i was more concerned about "write/read from - to" mechanic for both commands, so making math for how many bytes to read didn't sound as an option for me.(in other words "end parameter would be good to have along with "for how many to proceed")

Re: Readfile()/Writefile() start/end parameters.

Posted: 31 Aug 2022 10:30
by admin
It's already there but I had no time to talk about it in the change log:

Code: Select all

syntax: writefile(filename, data, [on_exist], [mode], [start=1], [numbytes=-1])
Example:

Code: Select all

writefile( , "abc",,,3,2); //writes "ab" at position 3 to the currently selected file

Re: Readfile()/Writefile() start/end parameters.

Posted: 31 Aug 2022 11:03
by eil
Thank you! Please update Help file when you'll have time.