From a85491459f780549181987aef910bfc0b416c668 Mon Sep 17 00:00:00 2001 From: Matt Bilker Date: Mon, 29 Oct 2018 15:53:27 +0000 Subject: [PATCH] bin: use new to_text_xml function --- Cargo.toml | 2 +- src/bin/kbinxml.rs | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f28a9a..94c4dc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kbinxml" -version = "0.13.3" +version = "0.13.4" authors = ["Matt Bilker "] [dependencies] diff --git a/src/bin/kbinxml.rs b/src/bin/kbinxml.rs index 2a7f445..6ad4e0b 100644 --- a/src/bin/kbinxml.rs +++ b/src/bin/kbinxml.rs @@ -10,12 +10,12 @@ extern crate quick_xml; use std::env; use std::fs::File; -use std::io::{Cursor, Error as IoError, ErrorKind as IoErrorKind, Read, Write, stdout}; +use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read, Write, stdout}; use failure::Fail; use kbinxml::{NodeCollection, Options, Printer}; use minidom::Element; -use quick_xml::{Reader, Writer}; +use quick_xml::Reader; cfg_if! { if #[cfg(feature = "serde")] { @@ -68,15 +68,6 @@ fn display_err(err: impl Fail) -> IoError { IoError::new(IoErrorKind::Other, "Error parsing kbin") } -fn to_text(element: &Element) -> Result, IoError> { - let inner = Cursor::new(Vec::new()); - let mut writer = Writer::new_with_indent(inner, b' ', 2); - element.to_writer(&mut writer).map_err(|e| IoError::new(IoErrorKind::Other, format!("{:?}", e)))?; - - let buf = writer.into_inner().into_inner(); - Ok(buf) -} - fn display_buf(buf: &[u8]) -> Result<(), IoError> { let stdout = stdout(); stdout.lock().write_all(&buf)?; @@ -233,10 +224,12 @@ fn main() -> std::io::Result<()> { if kbinxml::is_binary_xml(&contents) { Printer::run(&contents).unwrap(); - let (element, encoding_original) = kbinxml::element_from_binary(&contents).map_err(display_err)?; - let text_original = to_text(&element)?; + let (collection, _encoding) = kbinxml::from_slice(&contents).map_err(display_err)?; + let text_original = kbinxml::to_text_xml(&collection).map_err(display_err)?; display_buf(&text_original)?; + let (element, encoding_original) = kbinxml::element_from_binary(&contents).map_err(display_err)?; + let options = Options::with_encoding(encoding_original); let buf = kbinxml::to_binary_with_options(options, &element).map_err(display_err)?; compare_slice(&buf, &contents);