Struct libxivdat::dat_file::DATFile [−][src]
pub struct DATFile { /* fields omitted */ }
Expand description
A reference to an open DAT file on the system. This emulates the standard lib
std::fs::File
but provides additional DAT-specific functionality.
Reads and writes to DAT files are performed only on the data contents of the file. XOR masks are automatically applied as necessary.
Examples
use libxivdat::dat_file::DATFile; use libxivdat::dat_type::DATType; use std::io::Read; let mut dat_file = match DATFile::open("./resources/TEST_XOR.DAT") { Ok(dat_file) => dat_file, Err(_) => panic!("Something broke!") }; match dat_file.file_type() { DATType::Macro => { let mut macro_bytes = vec![0u8; dat_file.content_size() as usize - 1]; match dat_file.read(&mut macro_bytes) { Ok(count) => println!("Read {} bytes.", count), Err(_) => panic!("Reading broke!") } }, _ => panic!("Not a macro file!") };
Implementations
Returns the size of the current content contained in the DAT file. DAT files store content as a null-terminated CString, so this size is one byte larger than the actual content.
Examples
use libxivdat::dat_file::DATFile; let mut dat_file = DATFile::open("./resources/TEST.DAT").unwrap(); let content_size = dat_file.content_size();
Creates a new DAT file with an empty content block in read/write mode. This will truncate an existing file if one exists at the specified path.
By default, this will use the default max size for the specified type from
get_default_max_size_for_type()
and
default header ending from get_default_end_byte_for_type()
.
To cicumvent this behavior, you can use create_unsafe()
. Note
that DAT files with nonstandard sizes may produce undefined behavior in the game client.
Errors
If an I/O error creating the file occurs, a DATError::FileIO
error will be returned wrapping the underlying FS error.
Examples
use libxivdat::dat_file::DATFile; use libxivdat::dat_type::DATType; let mut dat_file = DATFile::create(&path, DATType::Macro);
Creates a new DAT file with a null-padded content bock of the specifed size in read/write mode. This will truncate an existing file if one exists at the specified path.
This function allows a custom, not-necessarily-valid maximum length and end byte to be set. Note that DAT files with nonstandard sizes and headers may produce undefined behavior in the game client.
Errors
If an I/O error creating the file occurs, a DATError::FileIO
error will be returned wrapping the underlying FS error.
Examples
use libxivdat::dat_file::DATFile; use libxivdat::dat_type::DATType; // Create an empty (content length 1) macro file with a custom max size and end byte. This probably isn't valid. let mut dat_file = DATFile::create_unsafe(&path, DATType::Macro, 1, 1024, 0x01);
Creates a new DAT file with a specific content block in read/write mode. This will truncate an existing file if one exists at the specified path.
This is shorthand for creating the DAT file, then calling
write()
. This function also resets the cursor to
the beginning of the content block after writing.
By default, this will use the default max size for the specified type from
get_default_max_size_for_type()
and
default header ending from get_default_end_byte_for_type()
.
To cicumvent this behavior, you can use create_unsafe()
. Note
that DAT files with nonstandard sizes may produce undefined behavior in the game client.
Errors
If an I/O error creating the file occurs, a DATError::FileIO
error will be returned wrapping the underlying FS error.
A DATError::Overflow
is returned
if the provided content size is too large, or if the content size exceeds the maximum size.
Examples
use libxivdat::dat_file::DATFile; use libxivdat::dat_type::DATType; let mut dat_file = DATFile::create_with_content(&path, DATType::Macro, b"Not really a macro.");
Returns the file type of the DAT file.
Examples
use libxivdat::dat_file::DATFile; use libxivdat::dat_type::DATType; let mut dat_file = DATFile::open("./resources/TEST_XOR.DAT").unwrap(); match dat_file.file_type() { DATType::Macro => println!("Macro file!"), _ => panic!("Nope!") }
Returns the terminating byte of the DAT file’s header. The purpose of this byte is unknown, but it is almost always 0xFF.
Examples
use libxivdat::dat_file::DATFile; let mut dat_file = DATFile::open("./resources/TEST_XOR.DAT").unwrap(); let header_end_byte = dat_file.header_end_byte();
Returns the maximum size allowed for the content block
of the DAT file. Content is stored as a null-terminated CString,
so the actual maximum allowed content is 1 byte less than max_size
.
Examples
use libxivdat::dat_file::DATFile; let mut dat_file = DATFile::open("./resources/TEST_XOR.DAT").unwrap(); let header_end_byte = dat_file.max_size();
Calls metadata()
on the underlying std::fs::File
.
Errors
This function will return any underling I/O errors as a
DATError::FileIO
.
Attempts to open a DAT file in read-only mode.
To set different file access with OpenOptions
,
use open_options()
Errors
If an I/O error opening the file occurs, a DATError::FileIO
error will be returned wrapping the underlying FS error.
A DATError::BadHeader
will be returned if the header
cannot be validated, indicating a non-DAT or corrupt file.
Examples
use libxivdat::dat_file::DATFile; let mut dat_file = DATFile::open("./resources/TEST.DAT");
pub fn open_options<P: AsRef<Path>>(
path: P,
options: &mut OpenOptions
) -> Result<Self, DATError>
pub fn open_options<P: AsRef<Path>>(
path: P,
options: &mut OpenOptions
) -> Result<Self, DATError>
Attempts to open a DAT file using an OpenOptions
builder.
A reference to the OpenOptions
struct itself should be passed in, not the File
it opens.
Do not end the options chain with open("foo.txt")
as with opening a standard file.
Errors
If an I/O error opening the file occurs, a DATError::FileIO
error will be returned wrapping the underlying FS error.
A DATError::BadHeader
will be returned if the header
cannot be validated, indicating a non-DAT or corrupt file.
Examples
use libxivdat::dat_file::DATFile; use std::fs::OpenOptions; let mut open_opts = OpenOptions::new(); open_opts.read(true).write(true); let mut dat_file = DATFile::open_options("./resources/TEST.DAT", &mut open_opts);
Truncates or extends the readable content section of the DAT file.
This emulates the behavior of std::fs::File::set_len()
, but only
operates on the content region of the DAT file. Because DAT files store
content as null-terminated CStrings, the actual writeable space will be
one byte less than specified.
Errors
This function will return any underling I/O errors as a
DATError::FileIO
.
Additionally, it may return a DATError::Overflow
error if the new content size would exceed the maximum allowed size. This size may be adjusted using
set_max_size()
, but modifying it may not produce a valid file for the game client.
Truncates or extends the full DAT file.
This emulates the behavior of std::fs::File::set_len()
.
Because DAT files store content as null-terminated CStrings,
the actual useable space will be one byte less than specified.
Files with a non-default maximum size may cause undefined behavior in the game client.
Errors
This function will return any underling I/O errors as a
DATError::FileIO
.
A DATError::Overflow
is returned
if the maximum size would be shorter than the content size after shrinking. To correct this,
first set_content_size()
.
Calls sync_all()
on the underlying std::fs::File
.
Errors
This function will return any underling I/O errors as a
DATError::FileIO
.
Calls sync_data()
on the underlying std::fs::File
.
Errors
This function will return any underling I/O errors as a
DATError::FileIO
.
Trait Implementations
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
read_initializer
)Determines if this Read
er can work with buffers of uninitialized
memory. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Read the exact number of bytes required to fill buf
. Read more
Creates a “by reference” adaptor for this instance of Read
. Read more
Creates an adaptor which will chain this stream with another. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Auto Trait Implementations
impl RefUnwindSafe for DATFile
impl UnwindSafe for DATFile