Page 1 of 1
File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 8:46 pm
by kaveh1000
I am writing some text to a file on disk using the standard procedure:
Code: Select all
open file my_file for text write
write fld "text" to file my_file
The file is getting truncated to specific numbers of characters and I notice the number of chars is a multiple of 4096, for instance:
4096
40960
61440
Any ideas pls?
Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 8:58 pm
by Klaus
Hi Kaveh,
does the shorter URL syntax work?
Code: Select all
...
put fld "text" into url("file:" & my_file)
...
?
Best
Klaus
Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 9:11 pm
by dunbarx
This works fine for me in v 8.1.10. The length of the text file is a bit over one Meg:
Code: Select all
on mouseUp
put "aslkjfhlasflsakflsalfklsakfjlskflsjf" into temp
repeat 15
put temp after temp
end repeat
answer the length of temp
put "/users/craignewman/desktop/XXX" into filePath
open file filePath for text write
write temp to file filePath
close file filePath
end mouseUp
Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 9:15 pm
by FourthWorld
Number of characters or number of bytes? How are you assessing that?
If assessment is from the file manager that's normal, as most OSes ship with a file system that uses a 4k block size by default.
That assumes, of course, that the number you're seeing is rounding up, rather than down, yes?
Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 9:29 pm
by kaveh1000
@Klaus:
Your solution seems to work. Thank you.
@Richard:
Number of chars, which is weird. I open in a text editor that shows no of chars. As I add characters to the top of the file, the same number are deleted from the bottom.
@Craig:
I am getting truncation even with very short text, e.g. truncated to 4096 chars.
Love to know the cause! Thank you to all as ever.

Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 9:32 pm
by kaveh1000
I have an "on idle" handler running while testing. I wonder if that could be the reason.
Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 9:36 pm
by ClipArtGuy
kaveh1000 wrote: ↑Tue Dec 18, 2018 9:32 pm
I have an "on idle" handler running while testing. I wonder if that could be the reason.
Can you use a "send in time" instead of idle? I can't remember where, but I was warned off of using idle unless absolutely necessary. Send in time works everywhere I've ever needed it.
There's this little bit from the livecode wiki:
Executing an idle handler slows down other LiveCode actions, so handle the idle message only in the rare cases where the send command cannot be used instead.
Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 10:00 pm
by FourthWorld
kaveh1000 wrote: ↑Tue Dec 18, 2018 9:32 pm
I have an "on idle" handler running while testing. I wonder if that could be the reason.
Depends on what it does. Please consider posting the simplest stack you can come up with which exhibits the problem.
Re: File written to disk truncated to multiples of 4096 chars
Posted: Tue Dec 18, 2018 10:26 pm
by kaveh1000
I'll try and make a minimal stack to post, Richard, but it is linked with some unfinished stuff that I can't post...
I can confirm it is not due to the idle handler. I have switched off and retested with same results.