pub fn from_stream<T: Read>(stream: T) -> io::Result<Self> {
        let mut reader = BufReader::new(stream);
        let mut counter = [0u64; 256];
        let mut something_read = false;
        loop {
            let buf = reader.fill_buf()?;
            let length = buf.len();
            if length == 0 {
                break;
            }
            something_read = true;
            for &byte in buf {
                counter[byte as usize] += 1;
            }
            reader.consume(length);
        }
        if !something_read {
            return Err(io::Error::new(io::ErrorKind::InvalidData, "Empty file"));
        }
        let tree = array::IntoIter::new(counter)
            .enumerate()
            .filter_map(|(byte, count)| (count != 0).then(|| (count, byte as u8)))
            .collect();
        Ok(tree)
    }
/// Consumes a stream and build a HuffmanTree from it.
Consumes a stream and build a HuffmanTree from it.
Consumes a stream and build a HuffmanTree from it .
pub fn from_stream<T: Read>(stream: T) -> io::Result<Self> {
        let mut reader = BufReader::new(stream);
        let mut counter = [0u64; 256];
        let mut something_read = false;
        loop {
            let buf = reader.fill_buf()?;
            let length = buf.len();
            if length == 0 {
                break;
            }
            something_read = true;
            for &byte in buf {
                counter[byte as usize] += 1;
            }
            reader.consume(length);
        }
        if !something_read {
            return Err(io::Error::new(io::ErrorKind::InvalidData, "Empty file"));
        }
        let tree = array::IntoIter::new(counter)
            .enumerate()
            .filter_map(|(byte, count)| (count != 0).then(|| (count, byte as u8)))
            .collect();
        Ok(tree)
    }
pub fn from_stream < T : Read > ( stream : T ) -> io :: Result < Self > { let mut reader = BufReader :: new ( stream ) ; let mut counter = [ 0u64 ; 256 ] ; let mut something_read = false ; loop { let buf = reader . fill_buf ( ) ? ; let length = buf . len ( ) ; if length == 0 { break ; } something_read = true ; for & byte in buf { counter [ byte as usize ] += 1 ; } reader . consume ( length ) ; } if ! something_read { return Err ( io :: Error :: new ( io :: ErrorKind :: InvalidData , " " ) ) ; } let tree = array :: IntoIter :: new ( counter ) . enumerate ( ) . filter_map ( | ( byte , count ) | ( count != 0 ) . then ( | | ( count , byte as u8 ) ) ) . collect ( ) ; Ok ( tree ) }
Consumes a stream and build a HuffmanTree from it.
Consumes a stream and build a HuffmanTree from it .
stream
T
stream
T