It is currently Sat May 27, 2017 11:40 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: 2 quick questions about byte.write.byte
Unread postPosted: Thu Apr 13, 2017 12:09 pm 
Offline
User avatar

Joined: Mon Mar 27, 2017 2:42 pm
Posts: 14
I was trying to rewrite the first two bytes of a file, which happened successfully. But the rest of the file was overwritten by FF (or -1 or EOF). Did I miss something in the manual?
Also, why can you only position the pointer in read mode? One would have to read an entire file into memory to change one byte in the middle. What am I missing?

Peace,
ReNoob


Report this post
Top
 Profile  
 
 Post subject: Re: 2 quick questions about byte.write.byte
Unread postPosted: Mon Apr 17, 2017 12:52 pm 
Offline
User avatar

Joined: Thu Nov 21, 2013 7:00 pm
Posts: 638
>What am I missing?
Not much.
That's right, file pointer positioning is only for reading.
>One would have to read an entire file into memory to change one byte in the middle
Yep.
You could try Byte.read.buffer and Byte.write.buffer for half the file and re-use the string
for the second half, that might save a bit of memory.

_________________
- Failure is not an option. It is bundled with the software. -


Report this post
Top
 Profile  
 
 Post subject: Re: 2 quick questions about byte.write.byte
Unread postPosted: Mon Apr 17, 2017 2:32 pm 
Offline
User avatar

Joined: Mon Mar 27, 2017 2:42 pm
Posts: 14
I was afraid of that. I'm gonna start working on that tonight. BTW, your signature is pure genius!


Report this post
Top
 Profile  
 
 Post subject: Re: 2 quick questions about byte.write.byte
Unread postPosted: Tue Apr 18, 2017 8:06 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
If you want to operate on a string buffer (read and write it), I found (waaay back when I wrote my RPG) that TEXT.WRITELN is hundreds time faster than BYTE.WRITE.BUFFER
The only inconvenient is that it adds a line feed (CHR$(10)) at the end of the buffer, but knowing that you can remove it when reading back the buffer...

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: 2 quick questions about byte.write.byte
Unread postPosted: Wed Apr 19, 2017 7:29 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 830
Unfortunately the mentioned additional [CHR$(13)&]CHR$(10) is not the only issue: because of utf-encoding of text-write-operations, the output differs in various ways. Therefore TEXT.WRITELN normally is not an alternative...which is a pitty because of the mentioned speed differences.

For-in our days common- filesizes of several MB, BYTE.WRITE.xxx is almost useless,because of unacceptable long time needed for writing.

For small files the time difference is negliable, as in example below (compare size/content of output-files)

regards, brochi


Code:
file_in$         = "meow.wav"

GRABFILE            file$, file_in$


BYTE.OPEN         w,fid, "meow_byteWrite.wav"
BYTE.WRITE.BUFFER   fid, file$
BYTE.CLOSE          fid

BYTE.OPEN         w,fid, "test_byteWrite.dat"
BYTE.WRITE.BUFFER   fid, "a"
BYTE.CLOSE          fid


TEXT.OPEN         w,fid, "meow_textWrite.wav"
TEXT.WRITELN        fid, file$
TEXT.CLOSE          fid

TEXT.OPEN         w,fid, "test_textWrite .dat"
TEXT.WRITELN        fid, "a"
TEXT.CLOSE          fid

END


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred