[][src]Struct rscache::Cache

pub struct Cache { /* fields omitted */ }

Main struct which provides basic cache utilities and interactions.

Implementations

impl Cache[src]

pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, CacheError>[src]

Constructs a new Cache.

The cache loads every file into memory.

Errors

If this function encounters any form of I/O or other error, a CacheError is returned which wrapps the underlying error.

Examples

use rscache::Cache;
 
let cache = Cache::new("path/to/cache");

pub fn read(
    &self,
    index_id: u8,
    archive_id: u16
) -> Result<LinkedList<&[u8]>, ReadError>
[src]

Reads from the internal main_file_cache.dat2 buffer.

A lookup is performed on the specified index to find the sector id and the total length of the buffer that needs to be read from the main_file_cache.dat2 buffer.

If the lookup is successfull the data is gathered into a LinkedList<&[u8]>.

Errors

Returns an IndexNotFound error if the specified index_id is not a valid Index.
Returns an ArchiveNotFound error if the specified archive_id is not a valid Archive.

Examples

let cache = Cache::new(path)?;
 
let index_id = 2; // Config index
let archive_id = 10; // Random archive.
 
let buffer = cache.read(index_id, archive_id)?;

pub fn create_checksum(&self) -> Result<Checksum, CacheError>[src]

Creates a Checksum which can be used to validate the cache data that the client received during the update protocol.

NOTE: The RuneScape client doesn't have a valid crc for index 16. This checksum sets the crc and revision for index 16 both to 0. The crc for index 16 should be skipped.

Errors

Returns an error when a buffer read from the reference table could not be decoded / decompressed.

Examples

let checksum = cache.create_checksum()?;

pub fn huffman_table(&self) -> Result<Vec<u8>, CacheError>[src]

Constructs a buffer which contains the huffman table.

Errors

Returns an error if the huffman archive could not be found or if the decode / decompression of the huffman table failed.

Examples

let huffman_table = cache.huffman_table()?;
let huffman = Huffman::new(huffman_table);

pub fn index_count(&self) -> usize[src]

Simply returns the index count, by getting the len() of the underlying indices vector.

Examples

for index in 0..cache.index_count() {
    // ...
}
 
assert_eq!(22, cache.index_count());

Trait Implementations

impl Clone for Cache[src]

impl Debug for Cache[src]

impl Default for Cache[src]

Auto Trait Implementations

impl RefUnwindSafe for Cache

impl Send for Cache

impl Sync for Cache

impl Unpin for Cache

impl UnwindSafe for Cache

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.