If I want to shorten a binary file, how can I do that?
When i use LOF(X) QB says the file has n length. Is it possible to trick QB so LOF(X) says n-1 length, or do I have to make a new shorter copy of the file?
________
Oregon Medical Marijuana Dispensaries
Cut binary file
Cut binary file
Last edited by nyfiken on Tue Feb 15, 2011 10:32 pm, edited 1 time in total.
- Codemss
- Veteran
- Posts: 124
- Joined: Sun Jun 24, 2007 6:49 am
- Location: Utrecht, The Netherlands
- Contact:
You mean you want to compress the file? :S
BTW, all the files can be opened with OPEN file$ FOR BINARY AS #1, it's actually not that they "are" binary files. They are just changed the binary way. I don't know about LOF(X) but I think it just returns the amount of bytes that that file uses.
Ow, wait... You mean you want to discard some bytes at the end of a file? Shit I don't know how to do that. I only know that you can change the bytes with PUT and GET. Maybe if you PUT a 0 at the end. I'm not sure though...
BTW, all the files can be opened with OPEN file$ FOR BINARY AS #1, it's actually not that they "are" binary files. They are just changed the binary way. I don't know about LOF(X) but I think it just returns the amount of bytes that that file uses.
Ow, wait... You mean you want to discard some bytes at the end of a file? Shit I don't know how to do that. I only know that you can change the bytes with PUT and GET. Maybe if you PUT a 0 at the end. I'm not sure though...
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Re: Cut binary file
Good question. You would think this would be easy, but I don't know any way.nyfiken wrote:If I want to shorten a binary file, how can I do that?
If the whole file fits in memory, you could read it in, close, open for output, close, and the write it out again.
Why bother, though, to shorten a file? What is your application? How did you wind up with spare space at the end?
I can imagine one doing this. I have records which have a deleted flag:
0 xxxx
0 xxxx
1 xxxx
0 xxxx
0 xxxx
1 xxxx
1 xxxx
etc.
I want to compress the file so all the undeleted records are at the front.
Easy
But now I want to get rid of the space at the end. My answer would be to not depend on LOF for the number of records, but instead, put some kind of header record at the front of the file. Now you don't mind the space at the end. You will use it someday when you add new records.
Mac
Shortening a file
Yes, as I already said "If the whole file fits in memory, you could read it in, close, open for output, close, and the write it out again."
But if the file won't fit, you have to create a new file.
If your one file is so big that there is no room for two on your disk, you are doomed.
So I suggested just leaving the file big and keep your own pointer (not LOF) to know where there is space to write new records to.
Mac
But if the file won't fit, you have to create a new file.
If your one file is so big that there is no room for two on your disk, you are doomed.
So I suggested just leaving the file big and keep your own pointer (not LOF) to know where there is space to write new records to.
Mac
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Makes sense! The record fields can be marked and overwritten in that case. To shorten the file is most likely a futile overature. You may have to add something to the file later!
I hope you are NOT thinking like Bill Gates and the 640K limit in his garage. Windows hogs memory and the hard drive, so keep the space in your Monster sized file............ It will never be that bloated!
Ted
I hope you are NOT thinking like Bill Gates and the 640K limit in his garage. Windows hogs memory and the hard drive, so keep the space in your Monster sized file............ It will never be that bloated!
Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0