1
0
Fork
You've already forked sf3-rust
0
An implementation of the Simple File Format Family in Rust. (Read-only Git mirror) https://git.average.name/AverageHelper/sf3-rust
  • Rust 99.4%
  • Shell 0.6%
2025年11月30日 18:13:49 -07:00
.forgejo/workflows chore(ci): update variable names 2025年08月04日 15:24:07 -06:00
examples chore: Cleaner archive example 2025年06月10日 13:11:17 -06:00
src fix: remove doc_auto_cfg 2025年11月30日 17:37:58 -07:00
tests feat: Update the CRC32 checksum based on new spec and samples 2025年07月01日 13:12:35 -06:00
.editorconfig chore: Initial boilerplate 2025年05月31日 23:41:20 -07:00
.gitignore fix: Don't read nonexistent lockfile 2025年06月04日 20:32:29 -06:00
.rustfmt.toml chore: Initial boilerplate 2025年05月31日 23:41:20 -07:00
Cargo.toml chore: v0.2.0 2025年11月30日 18:13:49 -07:00
CHANGELOG.md chore: v0.2.0 2025年11月30日 18:13:49 -07:00
FUNDING.yml chore: Initial boilerplate 2025年05月31日 23:41:20 -07:00
LICENSE chore: Initial boilerplate 2025年05月31日 23:41:20 -07:00
README.md doc: update upstream links 2025年08月12日 17:03:51 -06:00
test.sh feat(tests): don't recompile every time we run coverage 2025年07月01日 13:13:25 -06:00

SF3

An implementation of SF3 (Simple File Format Family) in Rust. See the spec and reference implementations at https://shirakumo.org/docs/sf3.

Warning

This crate is an experimental work-in-progress still early in the design phase. Expect major breaking changes in the near future.

Feedback is appreciated, either via an issue or contacting me directly!

Features

This crate is a work-in-progress. The following functions have been implemented and tested:

  • Read SF3 files from bytes in memory, a file on disc, or any std::io::Read reader
  • Read metadata or headers alone, for easy parsing of large files
  • Create new SF3 files of supported formats
  • MIME types and preferred file extensions for all supported formats
  • no_std support
  • Formats
    • Archive
    • Audio
    • Log
    • Text
    • ...

Roadmap

The following formats and functions have yet to be implemented:

  • Image
  • Model
  • Physics-Model
  • Table (serde serializer?)
  • Vector Graphic
  • Utilities for reading from important parts of SF3 files without needing to load the entire file into memory
  • Utilities for writing parts of SF3 files in-place, without needing to load the entire file into memory

Examples

See the examples directory. Run an example using cargo run --example <example>

Dependencies

Installation

This crate is available on crates.io and our own package registry. Add it to your project like so:

# via crates.io
cargo add sf3
# or via git.avg.name
cargo add --index sparse+https://git.average.name/api/packages/AverageHelper/cargo/ sf3

Note

crates.io does not allow packages to be published with dependencies on code published outside of crates.io. Only use our package registry if you intend to self-publish. See The Cargo Book for details.

Usage

Parse from memory:

usesf3::file::Sf3File;usesf3::Archive;letarchive_bytes: &[u8]=/* ... */;letarchive=Archive::parse_bytes(archive_bytes).unwrap();assert_eq!(archive.payload.len(),2);

Parse from file:

usesf3::file::Sf3File;usesf3::Archive;letfile=std::fs::File::open("/path/to/example.ar.sf3")?;letarchive=Archive::parse_file(file).unwrap();assert_eq!(archive.payload.len(),2);

Parse from Reader or custom buffer:

usesf3::file::Sf3File;usesf3::Archive;letstream: implstd::io::Read=/* ... */;letbuf=std::io::BufReader::new(stream);letarchive=Archive::parse_io(Box::new(buf)).unwrap();assert_eq!(archive.payload.len(),2);

MIME type (const compatible):

usemediatype::MediaType;// mime-types for specific formats
letarchive_type: MediaType=sf3::Archive::MIME;letaudio_type: MediaType=sf3::Archive::MIME;// mime-type for a general SF3 file (may change in future with IANA registration)
letsf3_type: MediaType=sf3::file::MIME;

Feature flags

std

This feature is enabled by default, and enables support for parsing files from Read types, and certain features in chrono, const-str, crc32fast, and half which require Rust's std crate. All functions work well enough without std, including parsing from byte slices and generating new byte representations of SF3 files, so if you're writing a no_std crate or targeting an environment where std isn't available but alloc and core are, then you may disable this feature without much consequence.

serde

Disabled by default. Enables serde support for chrono, half, and mediatype types.

Testing

Run code-coverage tests using the test.sh script.

Regular unit tests can be run using cargo test. Use the --no-default-features flag to test no_std support.

The tests/ directory contains sample files to test against. These are copied directly from the Shirakumo/sf3 repository, and may be out of date.

Contributing

Suggestions and code contributions are welcome! The codebase lives primarily at git.average.name, where you may file issues or pull requests using a fresh account there or an existing account with Codeberg or the like.

A read-only code mirror of this project also exists at Codeberg.

Acknowledgements

The SF3 spec was written by Yukari Hafner at Shirakumo, under the zlib License.

The API was somewhat inspired by the yaml and toml crates.