Skip to main content

ser_file/
lib.rs

1// SPDX-License-Identifier: MIT
2
3//! [![Crates.io](https://img.shields.io/crates/v/ser-file.svg)](https://crates.io/crates/ser-file)
4//! [![Docs.rs](https://docs.rs/ser-file/badge.svg)](https://docs.rs/ser-file)
5//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6//!
7//! Read, write, export, create SER files.
8//!
9//! This crate includes a lib and a cli (with the `"cli"` feature).
10//!
11//! Pre-built binary and library artifacts are available at [repo releases](https://github.com/themadcreator/ser-file/releases).
12//!
13//! #### Example: Export SER frames as PNGs
14//!
15//! ```rust,no_run
16//! use ser_file::Ser;
17//! use binrw::BinRead;
18//!
19//! use image::DynamicImage;
20//! use std::fs::File;
21//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
22//!
23//! // Read a SER file
24//! let mut file = File::open("example.ser")?;
25//! let ser = Ser::read(&mut file)?;
26//!
27//! // Save each frame as a PNG
28//! for (i, (frame, _timestamp)) in ser.into_iter().enumerate() {
29//!     let img: DynamicImage = frame.try_into()?;
30//!     img.save(format!("frame_{:02}.png", i))?;
31//! }
32//! # Ok(())
33//! # }
34//! ```
35//!
36//! #### Example: Create a SER containing a single PNG
37//!
38//! ```rust,no_run
39//! use ser_file::{Ser, FrameFormat};
40//! use binrw::BinWrite;
41//!
42//! use image;
43//! use std::{fs::File, io::BufWriter};
44//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
45//!
46//! // Read a PNG
47//! let img = image::open("example.png")?;
48//!
49//! // Create a format matching the image
50//! let format = FrameFormat::try_from(&img)?;
51//!
52//! // Create a new SER document
53//! let mut ser = Ser::with_format(format);
54//!
55//! // Add image as a frame
56//! let mut frames = ser.frames_mut();
57//! let frame = frames.format().try_into_frame(img)?;
58//! frames.try_push(frame, None)?;
59//!
60//! // Write
61//! let mut out = BufWriter::new(File::create("output.ser")?);
62//! ser.write(&mut out)?;
63//! # Ok(())
64//! # }
65//! ```
66//!
67//! #### Example: Use the cli
68//!
69//! ```text
70//! > cargo run --features cli --bin ser -- --help
71//! Read, write, export, create SER files
72//!
73//! Usage: ser <COMMAND>
74//!
75//! Commands:
76//!   info      Prints out information about a SER file
77//!   create    Creates a new SER file from a set of input images
78//!   export    Exports the frames from this SER file
79//!   validate  Validates this library by parsing and writing to memory and comparing the bytes
80//!   help      Print this message or the help of the given subcommand(s)
81//!
82//! Options:
83//!   -h, --help     Print help
84//!   -V, --version  Print version
85//! ```
86//!
87//! ```text
88//! > cargo run --features cli --bin ser -- info --in example.ser
89//! SER File example.ser
90//! Metadata:
91//!         Observer:   'Observer                                '
92//!         Instrument: 'ZWO ASI385MC                            '
93//!         Telescope:  'Telescope                               '
94//! Datetime:
95//!         Local:  2026-03-08 15:10:11.555915
96//!         UTC:    2026-03-08 22:10:11.555915
97//! Frame Format:
98//!         Color:  BAYER_BGGR
99//!         Depth:  U16(16)
100//!         Width:  1936
101//!         Height: 1096
102//! Frame Count: 10
103//! Frame Timestamps:
104//!         0:  2026-03-08 22:10:11.518220
105//!         1:  2026-03-08 22:10:11.537575
106//!         2:  2026-03-08 22:10:11.557111
107//!         3:  2026-03-08 22:10:11.576502
108//!         4:  2026-03-08 22:10:11.596097
109//!         5:  2026-03-08 22:10:11.615425
110//!         6:  2026-03-08 22:10:11.634807
111//!         7:  2026-03-08 22:10:11.654251
112//!         8:  2026-03-08 22:10:11.673783
113//!         9:  2026-03-08 22:10:11.693369
114//! ```
115//!
116
117mod fixed_string;
118mod format;
119mod ser;
120mod timestamp;
121pub use fixed_string::*;
122pub use format::*;
123pub use ser::*;
124pub use timestamp::*;