Difference between revisions of "Cache Format"

From RuneWiki
Jump to navigationJump to search
(New page: == General Information == The old engine cache is made up two types of files. === Data file === The data file holds all of the files in the cache and is named '''main_file_cache.dat'''....)
 
 
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
= Cache Format =
 +
 
== General Information ==
 
== General Information ==
  
Line 5: Line 7:
 
=== Data file ===
 
=== Data file ===
  
The data file holds all of the files in the cache and is named '''main_file_cache.dat'''. It is therefore very big, typically ~10-20 megabytes.
+
The data file holds all of the files in the cache and is named '''main_file_cache.dat'''. It is therefore very big, typically ~10-20 megabytes..
  
 
=== Index file ===
 
=== Index file ===
Line 11: Line 13:
 
There are several index files, named '''main_file_cache.idx''' and then postfixed with a number. Each index file holds 'pointers' to where a file is located in the main cache. Each index file represents a type of file.
 
There are several index files, named '''main_file_cache.idx''' and then postfixed with a number. Each index file holds 'pointers' to where a file is located in the main cache. Each index file represents a type of file.
  
== Index file format ==
+
== Format ==
 +
 
 +
=== Index file format ===
  
 
The index file is made up of 6 byte blocks which hold information about where a file can be located in the data file. The format of a single block is as follows:
 
The index file is made up of 6 byte blocks which hold information about where a file can be located in the data file. The format of a single block is as follows:
Line 18: Line 22:
 
  tribyte initialDataBlockId
 
  tribyte initialDataBlockId
  
The first block represents file 0, the second block represents file 1, and so on.
+
=== Data file format ===
 
 
The ''fileSize'' is the file size in bytes. The ''initialDataBlockId'' is the id of the ''first'' block in the data file which represents the specified file.
 
 
 
== Data file format ==
 
  
 
The data file is made up of 520 byte blocks. The format of each of these blocks is as follows:
 
The data file is made up of 520 byte blocks. The format of each of these blocks is as follows:
Line 32: Line 32:
 
  byte[512] blockData
 
  byte[512] blockData
  
Files, if necessary, are split up into multiple parts (i.e. if a single file is bigger than 512 bytes).
+
== Explanation ==
 +
 
 +
An example will be used here as it is easier to follow.
 +
 
 +
Let us say, the client wishes to fetch file type 2, file id 17.
 +
 
 +
First off, it will open the main_file_cache.idx2 file and seek to the index 17 * 6 (102). It will then read two tribytes.
 +
 
 +
fileSize = 1200
 +
intialDataBlockId = 4
 +
 
 +
The client will now open the main_file_cache.dat file and seek to the index 4 * 520 (2080). The values it reads will be:
 +
 
 +
nextFileId = 17
 +
currentFilePartId = 0
 +
nextDataBlockId = 5
 +
nextFileTypeId = 2
 +
blockData = ...
 +
 
 +
It will read the first 512 bytes of the file and then knows that there is 688 bytes left. Therefore, it has to read the next block.
 +
 
 +
nextFileId = 17
 +
currentFilePartId = 1
 +
nextDataBlockId = 6
 +
nextFileTypeId = 2
 +
blockData ...
 +
 
 +
It reads these next 512 bytes of the file and now knows that there are 176 bytes left. So for a final time, it will read the next block.
  
The ''nextFileId'' is the id of the next file in the block.
+
nextFileId = 18
The ''currentFilePartId'' is the part id of the current file. The first 520 byte block of a file will have id 0, the second will have 1, and so on.
+
currentFilePartId = 2
The ''nextDataBlockId'' is the id of the next 520 byte block of the file.
+
nextDataBlockId = 7
The ''nextFileTypeId'' is the id of the next file type. This should remain the same over a whole file.
+
nextFileTypeId = 2
 +
blockData = ...
  
The ''blockData'' is the part of the file data itself. It is always 512 bytes even if the part of the file is smaller.
+
It can ignore most of these values (the next ones are meaningless at this stage) and read the final 176 bytes. The whole 1200 byte file has now been read.

Latest revision as of 00:36, 9 December 2009

Cache Format

General Information

The old engine cache is made up two types of files.

Data file

The data file holds all of the files in the cache and is named main_file_cache.dat. It is therefore very big, typically ~10-20 megabytes..

Index file

There are several index files, named main_file_cache.idx and then postfixed with a number. Each index file holds 'pointers' to where a file is located in the main cache. Each index file represents a type of file.

Format

Index file format

The index file is made up of 6 byte blocks which hold information about where a file can be located in the data file. The format of a single block is as follows:

tribyte fileSize
tribyte initialDataBlockId

Data file format

The data file is made up of 520 byte blocks. The format of each of these blocks is as follows:

short nextFileId
short currentFilePartId
tribyte nextDataBlockId
byte nextFileTypeId
byte[512] blockData

Explanation

An example will be used here as it is easier to follow.

Let us say, the client wishes to fetch file type 2, file id 17.

First off, it will open the main_file_cache.idx2 file and seek to the index 17 * 6 (102). It will then read two tribytes.

fileSize = 1200
intialDataBlockId = 4

The client will now open the main_file_cache.dat file and seek to the index 4 * 520 (2080). The values it reads will be:

nextFileId = 17
currentFilePartId = 0
nextDataBlockId = 5
nextFileTypeId = 2
blockData = ...

It will read the first 512 bytes of the file and then knows that there is 688 bytes left. Therefore, it has to read the next block.

nextFileId = 17
currentFilePartId = 1
nextDataBlockId = 6
nextFileTypeId = 2
blockData ...

It reads these next 512 bytes of the file and now knows that there are 176 bytes left. So for a final time, it will read the next block.

nextFileId = 18
currentFilePartId = 2
nextDataBlockId = 7
nextFileTypeId = 2
blockData = ...

It can ignore most of these values (the next ones are meaningless at this stage) and read the final 176 bytes. The whole 1200 byte file has now been read.