1000byte limit on fileread

Report bugs. Post bug workarounds or fixes

Moderator: MSandro

Post Reply
SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

1000byte limit on fileread

Post by SimpleSi » Oct 23rd, '17, 16:26

I'm writing a GIF file parser and it works on small images but I can't read files bigger than 1000 bytes using
toBinaryData(readfile 'xxxx.gif')

I know some file primitives have been added to GP but I've been unable to work out how to use them

Help! :)
[EDIT]
There's not a 1000 byte limt - it was pure coincidence that it worked on a file < 1000 but failed on a file that was 1003 long

The bug seems to be not reading until the end of the file - I can get it to fail on files < 1000

my test code is
scriptImage5.png
scriptImage5.png (11.64 KiB) Viewed 3470 times
Here are some gif files that show issue

sample_1x8.gif
sample_1x8.gif (461 Bytes) Viewed 3470 times
is OK
sample_1x16.gif
sample_1x16.gif (1003 Bytes) Viewed 3470 times
is not

scratch.gif
scratch.gif (1.73 KiB) Viewed 3470 times
is not
scratch4col.gif
scratch4col.gif (939 Bytes) Viewed 3470 times
is not

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: 1000byte limit on fileread

Post by JohnM » Oct 23rd, '17, 22:41

This problem is that the "read file" block in the palette is not revealing the optional second parameter, a boolean that indicates that the file is binary. So you're files are getting truncated at the first EOF character encountered. Binary data typically has many EOF bytes (1 in 256 bytes, if the byte distribution were uniform).

I will fix that. Meanwhile, you can use the trusty "blockify" menu command in a Workspace to get a block with that parameter. Type:

readFile 'foo.gif' true

in a Workspace window, select it, then select "blockify it..." from the right-click menu.

Hope that helps!

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: 1000byte limit on fileread

Post by SimpleSi » Oct 24th, '17, 06:14

:)
readfile 'filename.txt' true

has fixed the issue :)

Post Reply