file-utils
This crate aims to provide convenient one-liners for file I/O operations that carry no dependencies and don't require unsafe code.
Furthermore, to ensure that multi-byte primitive types and pointers like usize
are encoded correctly, compilation of the crate will take into account:
- Architecture (32-bit vs 64-bit)
- Endianness
Usage
Reading binary
All the methods are implemented directly for any type that implements the Read
trait, so all you need to do is bring the traits into scope.
extern crate file_utils;
use io;
use File;
use Read; // <--- bring the Read trait into scope
All primitive number types can be read this way
;
;
// 8-bit
;
;
// 16-bit
;
;
// 32-bit
;
;
;
// 64-bit
;
;
;
Writing binary
Similarly to Read
, this crate provides its writing methods as implementations to any type that implements Write
.
extern crate file_utils;
use io;
use File;
use Write; // <--- bring the Write trait into scope