-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|697|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> File Access


 
Andy_A
Created : 04 February 2013
 
System : Windows
Language : Blitz

Any File to b64 BB data statements

Simple way to include pics with src

Creates a .bb file which can be posted with your source code. The .bb file can be run to save images or zips to disk.

Pros: Encodes files in a more compact format than decimal data and hex data.
Decimal data statements use ~3.57 bytes to encode 1 byte from file.
Hex data statements use ~2 bytes to encode 1 byte of data from file
b64 data statements use ~1.33 bytes to encode 1 byte of data from file
Fairly fast, I encoded a 45K jpg in 3 seconds (reading the input file, encoding the data, writing data to output file)

Cons: Large loader code adds ~950 bytes to data Too slow for realtime use



base64 encoded png (size = 2216 bytes):

 

Comments


Monday, 04 February 2013, 14:23
Jayenkai
Imagine that as a magazine type-in!! Good golly!!!

Nice work.
Monday, 04 February 2013, 16:03
Andy_A
Thanks!

Yeah, I tried to condense the loader code as much as possible. But hey!, it base64...

I already had a hex loader written up when it dawned on me that base64 is the better way to go.
Tuesday, 05 February 2013, 06:47
spinal
I remember QB4.5 progs that did this very nice.
Tuesday, 05 February 2013, 08:50
Andy_A
Looked at the QB src code and ran away. It uses base 86 stuff so I took the easy way out with base64.
Wednesday, 06 February 2013, 15:38
dna
This is probably a stupid wuestion but I cannot see the use for this.
Can someone give a specific example for this?
Wednesday, 06 February 2013, 15:42
Jayenkai
Protection. You have a set of sprites that you don't want people stealing, so you create the image from this data, load it, then delete it. That way, YOU can use it, but it won't be on the user's files, for easy access by them.
Wednesday, 06 February 2013, 16:28
dna
OH.
That partially explains it.
Thursday, 07 February 2013, 08:57
Andy_A
Another possible use: To post small (less then 15K) images, Dll's, or zip's along with source code. (no more 404's)
Thursday, 07 February 2013, 23:56
Afr0
If this was to be properly "protected", it would have to be encrypted. But I suppose just the sheer fact that it is encoded in the executable makes it somewhat harder to get at the file.