INNER CODE UNIT · Rust

view_file

atanunq/viu · src/app.rs:118

fn view_file(conf: &Config, filename: &str, (tx, rx): TxRx) -> ViuResult {
    if conf.name {
        println!("{}:", filename);
    }
    let mut file_in = fs::File::open(filename)?;

    // Read some of the first bytes to guess the image format
    let mut format_guess_buf: [u8; 20] = [0; 20];
    let _ = file_in.read(&mut format_guess_buf)?;
    // Reset the cursor
    file_in.seek(std::io::SeekFrom::Start(0))?;

    // If the file is a gif, let iTerm handle it natively
    if conf.viuer_config.use_iterm
        && viuer::is_iterm_supported()
        && (image::guess_format(&format_guess_buf[..])?) == image::ImageFormat::Gif
    {
        viuer::print_from_file(filename, &conf.viuer_config)?;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…