Pack files (.pak or sometimes .pck) are archive files. They contain other files, just like zip, rar and ace files. The difference is that pack file are usually not compressed, while zip andn rar files are. Pack files just contain all the files within one after another without compression, so it is similar to a directory. Because of this structure you don't have to decompress the pack file in order to read the files it contains. You can access them directly by using byte offset. For example, the file "firetex.pak" contains 3 fire textures - "fire1.jpg" from byte 1 to 100000, "fire2.jpg" from byte 100001 to 200000, "fire3.jpg" from byte 200001 to 300000. So, in order to access file "fire2.jpg" you open the pack file "firetex.pak" and start reading from byte 200001.
This method is very convenient, and used a lot by game developers. Because games contain hundreds of files, and the developers don't want you to be able to copy and use the files in your own game, they put all the small normal files into several big pack files. And then you see games with up to 20 large files, instead of 2000 files. For example, Battlefield Vietnam's data folder contains the files "animations.rfa", "menu.rfa", "sound.rfa" and so on. These are pack files, they just have a different extension. You can open these files, and most of the other pack files, with winzip or winrar. Creating them and reading them from your program is fairly easy.
To create a pack file:
rem Creating a packed file
print "Writing PAK file..."
open to write 1,"mydata.pak"
write fileblock 1,"grass05.bmp"
write fileblock 1,"Tile.bmp"
close file 1
rem Done
print "Done."
end
To read a pack file:
rem read
print "Reading PAK file into Temp folder..."
open to read 1,"mydata.pak"
if path exist("data")=1 then delete directory "data"
make directory "data"
set dir "data"
read fileblock 1,"grass05.bmp"
read fileblock 1,"Tile.bmp"
cd ".."
close file 1
remend
make matrix 3,1000,1000,20,20
load image "data\grass05.bmp",1
load image "data\Tile.bmp",2
PREPARE MATRIX TEXTURE 3,2,50,50
backdrop on
texture backdrop 1
do
print get dir$()
if spacekey()=1 then exit
loop
delete directory "data"
rem Done
print "Done."
end