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: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

File written to disk truncated to multiples of 4096 chars

Post by kaveh1000 » Tue Dec 18, 2018 8:46 pm

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: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Tue Dec 18, 2018 8:58 pm

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: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » Tue Dec 18, 2018 9:11 pm

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: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Tue Dec 18, 2018 9:15 pm

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: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

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

Post by kaveh1000 » Tue Dec 18, 2018 9:29 pm

@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: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

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

Post by kaveh1000 » Tue Dec 18, 2018 9:32 pm

I have an "on idle" handler running while testing. I wonder if that could be the reason.
Kaveh

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

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

Post by ClipArtGuy » Tue Dec 18, 2018 9:36 pm

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: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Tue Dec 18, 2018 10:00 pm

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: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

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

Post by kaveh1000 » Tue Dec 18, 2018 10:26 pm

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

Return to “Talking LiveCode”