sheave_core/flv/
not_flv_container.rs

1use std::{
2    error::Error,
3    fmt::{
4        Display,
5        Formatter,
6        Result as FormatResult
7    },
8    io::{
9        Error as IOError,
10        ErrorKind
11    }
12};
13
14/// An error that specified file isn't the FLV format.
15#[derive(Debug)]
16pub struct NotFlvContainer(String);
17
18impl Display for NotFlvContainer {
19    fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
20        writeln!(f, "Signature bytes are inconsistent: expected \"FLV\", actual {}.", &self.0)
21    }
22}
23
24impl Error for NotFlvContainer {}
25
26/// A utility function of constructing a `NotFlvContainer` error.
27pub fn not_flv_container<'a>(signature_bytes: &'a [u8]) -> IOError {
28    let signature = String::from_utf8(signature_bytes.into()).unwrap();
29    IOError::new(
30        ErrorKind::InvalidInput,
31        NotFlvContainer(signature)
32    )
33}