[][src]Crate redshirt

Provides support for the Redshirt 1 and Redshirt 2 data encoding schemes.

This crate provides utilities for reading and writing Redshirt 1- or Redshirt 2-encoded data. The Redshirt encoding schemes are used in Uplink, a 2001 computer hacking simulation game developed by Introversion Software.

Reading Redshirt data

redshirt provides v1::Reader for reading Redshirt 1 streams, and v2::Reader for reading Redshirt 2 streams:

use redshirt::v1::Reader;
use std::{fs::OpenOptions, io::Read};

fn main() {
    let file = OpenOptions::new().read(true).open("data.dat").unwrap();
    let mut reader = Reader::new(file).unwrap();
    let mut buffer = [u8::default(); 4];
    reader.read_exact(&mut buffer).unwrap();
    println!("{:#?}", buffer);
}

Both types offer the same features: support for reading and seeking via the standard Read and Seek traits, and destructuring to the underlying reader via Reader::into_inner.

Writing Redshirt data

redshirt provides v1::Writer for writing Redshirt 1 streams, and v2::Writer for writing Redshirt 2 streams:

use redshirt::v1::Writer;
use std::{fs::OpenOptions, io::Write};

fn main() {
    let file = OpenOptions::new().write(true).open("data.dat").unwrap();
    let mut writer = Writer::new(file).unwrap();
    let data = b"foobar";
    writer.write_all(&data[..]).unwrap();
}

Both types support writing via the standard Write trait, and destructuring to the underlying writer via Writer::into_inner. v1::Writer also supports seeking via the standard Seek trait. (See below for why v2::Writer doesn't support seeking.)

v2::Writer additional notes

Redshirt 2 stores a SHA-1 hash of the encoded data in the header. This means that using v2::Writer (which writes Redshirt 2 data) has two implications:

  • Seeking isn't supported, because it's costly to implement; the data would need to be re-read, and possibly stored in heap memory, in order to generate a correct hash.
  • Currently the SHA-1 hash is finalised and written into the header either when the v2::Writer is dropped, or when v2::Writer::into_inner is called. The drop call will panic if an error occurs, so it's highly recommended that you call into_inner, which returns a Result<T, Error> instead:
use redshirt::v2::Writer;
use std::{fs::OpenOptions, io::Write};

fn main() {
    let file = OpenOptions::new().write(true).open("User.usr").unwrap();
    let mut writer = Writer::new(file).unwrap();
    let data = b"foobar";
    writer.write_all(&data[..]).unwrap();
    let _ = writer.into_inner().unwrap(); // Triggers a panic if writing the checksum fails.
}

Modules

v1

Redshirt 1 utilities.

v2

Redshirt 2 utilities.

Enums

Error

Represents errors that may occur when working with Redshirt-encoded data.