File written to disk truncated to multiples of 4096 chars

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

File written to disk truncated to multiples of 4096 chars

Post 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?
Kaveh
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: File written to disk truncated to multiples of 4096 chars

Post by Klaus »

Hi Kaveh,

does the shorter URL syntax work?

Code: Select all

...
put fld "text" into url("file:" & my_file)
...
?

Best

Klaus
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: File written to disk truncated to multiples of 4096 chars

Post 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
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: File written to disk truncated to multiples of 4096 chars

Post 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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: File written to disk truncated to multiples of 4096 chars

Post 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. :-)
Kaveh
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: File written to disk truncated to multiples of 4096 chars

Post by kaveh1000 »

I have an "on idle" handler running while testing. I wonder if that could be the reason.
Kaveh
ClipArtGuy
Posts: 265
Joined: Wed Aug 19, 2015 4:29 pm

Re: File written to disk truncated to multiples of 4096 chars

Post 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.
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: File written to disk truncated to multiples of 4096 chars

Post 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: File written to disk truncated to multiples of 4096 chars

Post 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.
Kaveh
Post Reply