ages_prs/
lib.rs

1//! Compression and decompression of SEGA's LZ77 encoding, PRS, named after the
2//! file extension typically used for data encoded with it.
3//!
4//! There are two supported variants of PRS: Legacy and Modern. The compression
5//! and decompression routines are split between these two variants. Which
6//! variant to use depends on what game you are targeting the data for. For
7//! example, _Phantasy Star Online_ (2000) uses Legacy variant, and _Phantasy
8//! Star Online 2_ (2012) uses Modern variant. Not using the correct variant
9//! will likely result in undefined behavior in the targeted game, but this
10//! library will try to produce an Error if there would result in memory-unsafe
11//! copies in the command stream. That said, there is no way to _detect_ what
12//! kind of PRS variant a given buffer is in.
13//!
14//! # Examples
15//!
16//! Compress and decompress a buffer:
17//!
18//! ```
19//! use std::io::{Cursor, Read, Write};
20//!
21//! use ages_prs::{ModernPrsDecoder, ModernPrsEncoder};
22//!
23//! let input = b"Hello Hello Hello ";
24//! let mut encoder = ModernPrsEncoder::new(Vec::new());
25//! encoder.write_all(input).unwrap();
26//! let compressed = encoder.into_inner().unwrap();
27//!
28//! let mut decoder = ModernPrsDecoder::new(Cursor::new(&compressed[..]));
29//! let mut decomp = Vec::new();
30//! decoder.read_to_end(&mut decomp).unwrap();
31//! assert_eq!(&decomp[..], &input[..]);
32//! ```
33
34mod compress;
35mod decompress;
36mod variant;
37
38pub use self::compress::{PrsEncoder, IntoInnerError};
39pub use self::decompress::PrsDecoder;
40
41pub use self::variant::{
42    Variant,
43    Legacy,
44    Modern,
45};
46
47pub type ModernPrsEncoder<W> = PrsEncoder<W, Modern>;
48pub type LegacyPrsEncoder<W> = PrsEncoder<W, Legacy>;
49pub type ModernPrsDecoder<R> = PrsDecoder<R, Modern>;
50pub type LegacyPrsDecoder<R> = PrsDecoder<R, Legacy>;
51
52#[cfg(test)]
53mod test;