Page 1 of 1

Function readfile() doesn't read large files

Posted: 10 Jan 2016 03:30
by waqu
I use this code to copy files:

Code: Select all

 writefile("I:\Temp\file.avi",readfile("D:\Temp\file.avi","b"),,"b");
Files size over 100 MB copied incompletely, but only the first 100Mb.

Re: Function readfile() don't read large file

Posted: 10 Jan 2016 03:44
by highend
Iirc, the limit is by design.

Why are you trying to copy an .avi file by readfile / writefile?

Re: Function readfile() don't read large file

Posted: 10 Jan 2016 04:21
by waqu
highend wrote:Iirc, the limit is by design.

Why are you trying to copy an .avi file by readfile / writefile?
I need to merge multiple files into one.

Re: Function readfile() doesn't read large files

Posted: 10 Jan 2016 07:21
by highend
Use the dos copy command instead (with run / runret):

Code: Select all

copy /b file1+file2+file3 targetFile

Re: Function readfile() doesn't read large files

Posted: 10 Jan 2016 11:09
by PeterH
You *could* also test for file size, and if too big, copy parts of the file in a loop.
(readfile() knows operands for numbytes and start)

But in general highends solution seems more straightforward :tup:

Re: Function readfile() doesn't read large files

Posted: 10 Jan 2016 12:16
by highend
It's a kind of operation I wouldn't do with XY just because you block it while the script is running and assembling large video files is (on non ssds) a time consuming process so it's better to externalize it (at least if you don't want to use a XY instance only for this task).

Re: Function readfile() doesn't read large files

Posted: 10 Jan 2016 13:36
by waqu
highend wrote:Use the dos copy command instead (with run / runret):

Code: Select all

copy /b file1+file2+file3 targetFile
I need after the merger split file of the same size.

Re: Function readfile() doesn't read large files

Posted: 10 Jan 2016 13:52
by highend
Then use PeterH's method or a command line splitting tool?

E.g.:
http://www.lawrencegoetz.com/programs/gfs101.zip

or
split from:
http://sourceforge.net/projects/unxutils/

Re: Function readfile() doesn't read large files

Posted: 11 Jan 2016 13:43
by admin
FYI, upcoming change log has a tip:

Code: Select all

    > SC readfile: 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.
      This information has been missing from the help so far. Will be added soon.

Re: Function readfile() doesn't read large files

Posted: 11 Jan 2016 15:32
by SkyFrontier
'start' method is obsolete/innacurate/inadequate since XY started distinguishing double-byte chars, isn't it?
(written completely by bad memory, as I stumbled on this often in the past)

Re: Function readfile() doesn't read large files

Posted: 11 Jan 2016 16:30
by admin
Not at all! In the case of double-byte chars "start" points to the character position. Easy and intuitive to use.

Re: Function readfile() doesn't read large files

Posted: 11 Jan 2016 16:55
by SkyFrontier
I recall I had problems because XY was auto-detecting and forcing readfile() to interpret sections as single or double chars, leading to said innacuracy... Can this be user driven?

Re: Function readfile() doesn't read large files

Posted: 11 Jan 2016 16:59
by admin
Did some tests: no problems visible.

Re: Function readfile() doesn't read large files

Posted: 11 Jan 2016 23:07
by PeterH
admin wrote:In the case of double-byte chars "start" points to the character position. Easy and intuitive to use.

Code: Select all

    > SC readfile: 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.
      This information has been missing from the help so far. Will be added soon.
      Note that the "start" parameter points to the *character* position in case
      of text files (in double-byte encodings this is different from the byte
      position).
Docu (maybe old?) says:
numbytes: number of bytes to read
start: byte position to read from

OK: if numbytes and start are consistent, this "charcount" may be fine.

But note: if max 100MB may be read, numbytes (being chars!) *must* be sufficient smaller for multibyte charsets?
(Else it would be 100Mchars :biggrin: )

Re: Function readfile() doesn't read large files

Posted: 12 Jan 2016 11:03
by admin
Yes, Help needs and upgrade here...