fitsrs/file.rs
1use crate::gz::GzReader;
2use crate::Fits;
3use std::fs::File;
4use std::io::BufReader;
5use std::path::Path;
6
7/// This offers a method to open a file and provide a HDU list iterator over it
8///
9/// The opening process handle externally gzipped files
10///
11/// The downside is that the GzReader does not impl Seek, even if the original file is not gzipped
12/// Therefore, seek method will not be used to get to the next HDU after parsing an HDU
13/// If you know that your file is not externally gzipped, then you can directly use the Fits::from_reader method and providing
14/// it a Seekable reader
15#[derive(Debug)]
16pub struct FITSFile;
17
18use std::fmt::Debug;
19
20use crate::error::Error;
21impl FITSFile {
22 /// Open a fits file from a path. Can be gzip-compressed
23 pub fn open<P: AsRef<Path>>(path: P) -> Result<Fits<GzReader<BufReader<File>>>, Error> {
24 let f = File::open(path)?;
25 let bufreader = BufReader::new(f);
26 // Decorate the reader with a gz decoder
27 let reader = GzReader::new(bufreader)?;
28
29 Ok(Fits::from_reader(reader))
30 }
31}