Skip to content

Commit

Permalink
Added an example in the readme and lib documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ifeherva committed Aug 7, 2017
1 parent bf52089 commit f4b390a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,31 @@
This crate provides a Rust wrapper around [crunch's](https://github.com/BinomialLLC/crunch) decompressor.

[Documentation](https://docs.rs/decrunch/0.1.0/)

# Example

```
use decrunch::*;
use std::fs::File;
use std::io::Read;
# use std::io;
# fn foo() -> io::Result<()> {
let mut compressed_file = File::open("testdata/copyright_2048_compressed.dat")?;
let mut compressed_data = Vec::new();
compressed_file.read_to_end(&mut compressed_data)?;
let c_data = CrunchedData::new(&compressed_data);
let decompressed_data = match c_data.decode_level(0) {
None => {
panic!("Failed to decompress texture data");
}
Some(res) => res,
};
assert!(decompressed_data.len() > 0);
# Ok(())
# }
```
33 changes: 33 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//! # Decoder for crunch-compressed texture data
//!
//! This crate provides a Rust wrapper around [crunch's](https://github.com/BinomialLLC/crunch) decompressor.
//!
//! # Example
//!
//! ```
//! use decrunch::*;
//! use std::fs::File;
//! use std::io::Read;
//!
//! # use std::io;
//! # fn foo() -> io::Result<()> {
//! let mut compressed_file = File::open("testdata/copyright_2048_compressed.dat")?;
//! let mut compressed_data = Vec::new();
//!
//! compressed_file.read_to_end(&mut compressed_data)?;
//!
//! let c_data = CrunchedData::new(&compressed_data);
//! let decompressed_data = match c_data.decode_level(0) {
//! None => {
//! panic!("Failed to decompress texture data");
//! }
//! Some(res) => res,
//! };
//!
//! assert!(decompressed_data.len() > 0);
//!
//! # Ok(())
//! # }
//! ```

extern crate libc;

mod crunch;
Expand Down

0 comments on commit f4b390a

Please sign in to comment.