pub fn decompress_swf<'a, R: Read + 'a>(mut input: R) -> Result<SwfBuf> {
    // Read SWF header.
    let compression = read_compression_type(&mut input)?;
    let version = input.read_u8()?;
    let uncompressed_length = input.read_u32::<LittleEndian>()?;

    // Now the SWF switches to a compressed stream.
    let mut decompress_stream: Box<dyn Read> = match compression {
        Compression::None => Box::new(input),
        Compression::Zlib => {
            if version < 6 {
                log::warn!(
                    "zlib compressed SWF is version {} but minimum version is 6",
                    version
                );
            }
            make_zlib_reader(input)?
        }
        Compression::Lzma => {
            if version < 13 {
                log::warn!(
                    "LZMA compressed SWF is version {} but minimum version is 13",
                    version
                );
            }
            // Uncompressed length includes the 4-byte header and 4-byte uncompressed length itself,
            // subtract it here.
            make_lzma_reader(input, uncompressed_length - 8)?
        }
    };

    // Decompress the entire SWF.
    let mut data = Vec::with_capacity(uncompressed_length as usize);
    if let Err(e) = decompress_stream.read_to_end(&mut data) {
        log::error!("Error decompressing SWF: {}", e);
    }

    // Some SWF streams may not be compressed correctly,
    // (e.g. incorrect data length in the stream), so decompressing
    // may throw an error even though the data otherwise comes
    // through the stream.
    // We'll still try to parse what we get if the full decompression fails.
    // (+ 8 for header size)
    if data.len() as u64 + 8 != uncompressed_length as u64 {
        log::warn!("SWF length doesn't match header, may be corrupt");
    }

    let mut reader = Reader::new(&data, version);
    let stage_size = reader.read_rectangle()?;
    let frame_rate = reader.read_fixed8()?;
    let num_frames = reader.read_u16()?;
    let header = Header {
        compression,
        version,
        uncompressed_length,
        stage_size,
        frame_rate,
        num_frames,
    };
    let data = reader.get_ref().to_vec();
    Ok(SwfBuf { header, data })
}
/// Parses an SWF header and returns a `Reader` that can be used
/// to read the SWF tags inside the SWF file.
///
/// Returns an `Error` if this is not a valid SWF file.
///
/// # Example
/// ```
/// # std::env::set_current_dir(env!("CARGO_MANIFEST_DIR"));
/// let data = std::fs::read("tests/swfs/DefineSprite.swf").unwrap();
/// let swf_stream = swf::decompress_swf(&data[..]).unwrap();
/// println!("FPS: {}", swf_stream.header.frame_rate);
/// ```
Parses an SWF header and returns a `Reader` that can be used
to read the SWF tags inside the SWF file.

Returns an `Error` if this is not a valid SWF file.
Parses an SWF header and returns a ` Reader ` that can be used to read the SWF tags inside the SWF file . Returns an ` Error ` if this is not a valid SWF file .
pub fn decompress_swf<'a, R: Read + 'a>(mut input: R) -> Result<SwfBuf> {
    // Read SWF header.
    let compression = read_compression_type(&mut input)?;
    let version = input.read_u8()?;
    let uncompressed_length = input.read_u32::<LittleEndian>()?;
    // Now the SWF switches to a compressed stream.
    let mut decompress_stream: Box<dyn Read> = match compression {
        Compression::None => Box::new(input),
        Compression::Zlib => {
            if version < 6 {
                log::warn!(
                    "zlib compressed SWF is version {} but minimum version is 6",
                    version
                );
            }
            make_zlib_reader(input)?
        }
        Compression::Lzma => {
            if version < 13 {
                log::warn!(
                    "LZMA compressed SWF is version {} but minimum version is 13",
                    version
                );
            }
            // Uncompressed length includes the 4-byte header and 4-byte uncompressed length itself,
            // subtract it here.
            make_lzma_reader(input, uncompressed_length - 8)?
        }
    };
    // Decompress the entire SWF.
    let mut data = Vec::with_capacity(uncompressed_length as usize);
    if let Err(e) = decompress_stream.read_to_end(&mut data) {
        log::error!("Error decompressing SWF: {}", e);
    }
    // Some SWF streams may not be compressed correctly,
    // (e.g. incorrect data length in the stream), so decompressing
    // may throw an error even though the data otherwise comes
    // through the stream.
    // We'll still try to parse what we get if the full decompression fails.
    // (+ 8 for header size)
    if data.len() as u64 + 8 != uncompressed_length as u64 {
        log::warn!("SWF length doesn't match header, may be corrupt");
    }
    let mut reader = Reader::new(&data, version);
    let stage_size = reader.read_rectangle()?;
    let frame_rate = reader.read_fixed8()?;
    let num_frames = reader.read_u16()?;
    let header = Header {
        compression,
        version,
        uncompressed_length,
        stage_size,
        frame_rate,
        num_frames,
    };
    let data = reader.get_ref().to_vec();
    Ok(SwfBuf { header, data })
}
pub fn decompress_swf < ' a , R : Read + ' a > ( mut input : R ) -> Result < SwfBuf > { // Read SWF header. let compression = read_compression_type ( & mut input ) ? ; let version = input . read_u8 ( ) ? ; let uncompressed_length = input . read_u32 :: < LittleEndian > ( ) ? ; // Now the SWF switches to a compressed stream. let mut decompress_stream : Box < dyn Read > = match compression { Compression :: None => Box :: new ( input ) , Compression :: Zlib => { if version < 6 { log :: warn ! ( " " version ) ; } make_zlib_reader ( input ) ? } Compression :: Lzma => { if version < 13 { log :: warn ! ( " " version ) ; } // Uncompressed length includes the 4-byte header and 4-byte uncompressed length itself, // subtract it here. make_lzma_reader ( input , uncompressed_length - 8 ) ? } } ; // Decompress the entire SWF. let mut data = Vec :: with_capacity ( uncompressed_length as usize ) ; if let Err ( e ) = decompress_stream . read_to_end ( & mut data ) { log :: error ! ( " " e ) ; } // Some SWF streams may not be compressed correctly, // (e.g. incorrect data length in the stream), so decompressing // may throw an error even though the data otherwise comes // through the stream. // We'll still try to parse what we get if the full decompression fails. // (+ 8 for header size) if data . len ( ) as u64 + 8 != uncompressed_length as u64 { log :: warn ! ( " " ) ; } let mut reader = Reader :: new ( & data , version ) ; let stage_size = reader . read_rectangle ( ) ? ; let frame_rate = reader . read_fixed8 ( ) ? ; let num_frames = reader . read_u16 ( ) ? ; let header = Header { compression , version , uncompressed_length , stage_size , frame_rate , num_frames , } ; let data = reader . get_ref ( ) . to_vec ( ) ; Ok ( SwfBuf { header , data } ) }
Parses an SWF header and returns a `Reader` that can be used
to read the SWF tags inside the SWF file.
Parses an SWF header and returns a ` Reader ` that can be used to read the SWF tags inside the SWF file .
input
R
input
R
example
None
std::env::set_current_dir(env!("cargo_manifest_dir"));
let data = std::fs::read("tests/swfs/DefineSprite.swf").unwrap();
let swf_stream = swf::decompress_swf(&data[..]).unwrap();
println!("FPS: {}", swf_stream.header.frame_rate);
```
let data = std :: fs :: read ( " tests / swfs / DefineSprite . swf " ) . unwrap () ; let swf_stream = swf :: decompress_swf ( &data [ .. ] ) . unwrap () ; println! ( " FPS : {} " swf_stream . header . frame_rate ) ; ` ` `