Page 1 of 2
Writing in a file
Posted: Fri Jan 20, 2006 1:05 pm
by Inf0Byt3
Hello guys. I've been playing with the file functions and I wanted to ask you something: I need to create a file and write in it the contents of a memory buffer, but I want to display the progress for this.
If I use WriteData() i can't know how many bits were written. I tried something like this:
Code: Select all
global *a
if createfile(0,"test.bin")
for i = 1 to length
writebyte(peekb(*a))
;show progress
next i
closefile(0)
endif
The problem is that the file is being created but it's empty

So can anybody please help??? Thanx in advance...
Posted: Fri Jan 20, 2006 2:00 pm
by El_Choni
If length=0, no bytes will be written to the file and it'll be empty.
Posted: Fri Jan 20, 2006 2:06 pm
by Inf0Byt3
I've checked it and the length is > 0. Any suggestions?
Re: Writing in a file
Posted: Fri Jan 20, 2006 2:54 pm
by SFSxOI
never mind, it was stupid question anyway

Posted: Fri Jan 20, 2006 3:00 pm
by El_Choni
If you don't post the entire code, I can't help. In the code you posted, length=0.
Posted: Fri Jan 20, 2006 7:53 pm
by Inf0Byt3
AAA.. You were right. I defined the length as global and I was equalizing it with zero. I am stupid!!! Now the file gets created but it's very slow (200 kb/s). I'll post the code as soon as I can. Thanks!
Posted: Sat Jan 21, 2006 7:21 pm
by Inf0Byt3
This isn't good either. I was working on an installer and when the user executes is, the installer writes the data pack to a temporary file. I cannot post it because it has many includes and i don't want to release the source for it (yet). The problem is that i want to show the progress when writing to the temp file. Is there a way to do this?
Posted: Sun Jan 22, 2006 11:15 am
by wcardoso
don't refresh the progress bar each byte you write to the file, do it every 10 or 20 bytes.

Posted: Sun Jan 22, 2006 1:15 pm
by Inf0Byt3
Thanks for the tip, but i cannot show the progress at all, because I don't know how many bytes I've written to the file. If I use writebyte() method, it's very slow. If I use WriteData() i don't know how many bytes were written

.
Posted: Sun Jan 22, 2006 1:27 pm
by Dare2
Just curious, how do you use WriteData without the length parameter?
Posted: Sun Jan 22, 2006 2:40 pm
by Inf0Byt3
I have the total amount of data I have to write:
Code: Select all
global *a
global length ;assume that length = 2312312 for example
if createfile(0,"test.bin")
for i = 1 to length ; I have the length
writedata(*a,length)
Progress = length - a ;????? -> How much was written?
next i
closefile(0)
endif
To show a progress, i need to know the total length, wich I KNOW and how much was written, right??? Then I calculate ?% of length is the data was written, right?
Posted: Sun Jan 22, 2006 2:44 pm
by Trond
Inf0Byt3 wrote:Thanks for the tip, but i cannot show the progress at all, because I don't know how many bytes I've written to the file. If I use writebyte() method, it's very slow. If I use WriteData() i don't know how many bytes were written

.
Use WriteData() in 100 chunks.
For example, if you want to write 100 bytes, you execute WriteData() 100 times, writing one byte each time and updating the progress bar in between.
If you want to write 100 000 bytes you execute WriteData() 100 times, writing (100 000 / 100 =) 1000 bytes each time, updating the progress bar in between.
If you want to write 10 000 000 you execute WriteData() 100 times, writing (10 000 000 / 100 =) 100 000 bytes each time, updating the progress bar in between.
Dare2 wrote:Just curious, how do you use WriteData without the length parameter?
You can't, it's mandatory.
Posted: Sun Jan 22, 2006 2:48 pm
by Inf0Byt3
Damn, you're right, Trond!!! Why didn't I ever think of this????
Thanks. I'll try it now.
Posted: Sun Jan 22, 2006 2:55 pm
by Dare2
Trond wrote:Dare2 wrote:Just curious, how do you use WriteData without the length parameter?
You can't, it's mandatory.

Posted: Sun Jan 22, 2006 3:01 pm
by Trond
Dare2 wrote:Trond wrote:Dare2 wrote:Just curious, how do you use WriteData without the length parameter?
You can't, it's mandatory.

Or if you're desperate, everything is possible:
Code: Select all
!push 5
!call _PB_WriteData@8
End
WriteData(1, 0)