ebarnard / rust-plist

A rusty plist parser.
MIT License
71 stars 42 forks source link

Parser hangs #1

Closed robmiller closed 8 years ago

robmiller commented 9 years ago

Hello! I realise this library is a work in progress, but I wanted to try it out because I happen to a) need to parse some plist data and b) want to continue learning Rust. Feel free, therefore, to tell me "bugger off, this doesn't work yet".

I'm using the parser as follows, to read from the output of the system_profiler command:

extern crate plist;

use std::process::Command;
use std::io::{Read,Seek,SeekFrom,Cursor};
use plist::StreamingParser;

fn main() {
    println!("Profiling system.");

    let profiler = Command::new("system_profiler")
                           .arg("-xml")
                           .arg("-detailLevel")
                           .arg("basic")
                           .output()
                           .unwrap_or_else(|e| { panic!("Failed to spawn system profiler: {}", e) });

    let xml = String::from_utf8_lossy(&profiler.stdout).into_owned();

    println!("Parsing XML.");

    let mut stdout = Cursor::new(xml.into_bytes());

    let parser = StreamingParser::new(stdout);

    println!("Parser created.");

    for event in parser {
        println!("{:?}", event);
    }
}

However, this just hangs indefinitely on the for loop — I guess because the next() call in xml-rs is blocking, and so it's as though it's not receiving any input. I've tried rewinding the stream before passing it into StreamingParser::new and the same still happens.

Is this just a case of the library not being finished, or am I doing something obviously wrong that I can fix?

Thanks in advance, Rob

ebarnard commented 9 years ago

It's nice to know someone else is using this even if it if quite flaky.

No. You're not doing anything wrong. That plist managed to trigger five separate bugs but it should now work. Try with the latest version (0.0.8).