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

Features wanted...
Post Reply
eil
Posts: 1609
Joined: 13 Jan 2011 19:44

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

Post 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)
Win 7 SP1 x64 100% 1366x768

eil
Posts: 1609
Joined: 13 Jan 2011 19:44

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

Post by eil »

Scripting got lots of updates recently, maybe it's time for this?..
Win 7 SP1 x64 100% 1366x768

klownboy
Posts: 4090
Joined: 28 Feb 2012 19:27

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

Post 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) 
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

eil
Posts: 1609
Joined: 13 Jan 2011 19:44

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

Post 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")
Win 7 SP1 x64 100% 1366x768

admin
Site Admin
Posts: 60290
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

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

Post 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

eil
Posts: 1609
Joined: 13 Jan 2011 19:44

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

Post by eil »

Thank you! Please update Help file when you'll have time.
Win 7 SP1 x64 100% 1366x768

Post Reply