wsi_streamer/
lib.rs

1//! # WSI Streamer
2//!
3//! A tile server for Whole Slide Images (WSI) stored in S3-compatible object storage.
4//!
5//! This library provides the core functionality for serving tiles from
6//! Whole Slide Images stored in cloud object storage using HTTP range requests.
7//! It streams tiles directly without downloading entire files, making it ideal
8//! for large medical imaging files (1-10GB+).
9//!
10//! ## Features
11//!
12//! - **Range-based streaming**: Fetches only the bytes needed for each tile via HTTP range requests
13//! - **Format support**: Native parsers for Aperio SVS and pyramidal TIFF formats
14//! - **Multi-level caching**: Caches slides, blocks, and encoded tiles for performance
15//! - **Built-in web viewer**: Includes OpenSeadragon-based viewer
16//! - **Authentication**: Optional HMAC-SHA256 signed URL authentication
17//!
18//! ## Architecture
19//!
20//! The library is organized into several modules:
21//!
22//! - [`io`] - I/O layer with S3 range reader and block caching
23//! - [`mod@format`] - TIFF/SVS parsers and JPEG handling
24//! - [`slide`] - Slide abstraction and registry
25//! - [`tile`] - Tile service and encoding
26//! - [`server`] - Axum-based HTTP server and routes
27//! - [`config`] - CLI and configuration types
28//!
29//! ## Example
30//!
31//! ```rust,no_run
32//! use wsi_streamer::Cli;
33//! use clap::Parser;
34//!
35//! #[tokio::main]
36//! async fn main() {
37//!     // Parse CLI arguments (e.g., `wsi-streamer s3://my-bucket`)
38//!     let cli = Cli::parse();
39//!
40//!     match cli.into_command() {
41//!         wsi_streamer::Command::Serve(config) => {
42//!             // Validate and start the server
43//!             config.validate().expect("Invalid configuration");
44//!             println!("Starting server on {}", config.bind_address());
45//!         }
46//!         wsi_streamer::Command::Sign(config) => {
47//!             // Generate signed URL
48//!         }
49//!         wsi_streamer::Command::Check(config) => {
50//!             // Validate S3 connectivity
51//!         }
52//!     }
53//! }
54//! ```
55
56pub mod config;
57pub mod error;
58pub mod format;
59pub mod io;
60pub mod server;
61pub mod slide;
62pub mod tile;
63
64// Re-export commonly used types
65pub use config::{CheckConfig, Cli, Command, Config, ServeConfig, SignConfig, SignOutputFormat};
66pub use error::{FormatError, IoError, TiffError, TileError};
67pub use format::tiff::{
68    check_compression, check_tile_tags, check_tiled, parse_u32_array, parse_u64_array,
69    validate_ifd, validate_ifd_strict, validate_level, validate_pyramid, ByteOrder, Compression,
70    FieldType, Ifd, IfdEntry, PyramidLevel, TiffHeader, TiffPyramid, TiffTag, TileData,
71    ValidationError, ValidationResult, ValueReader, BIGTIFF_HEADER_SIZE, TIFF_HEADER_SIZE,
72};
73pub use format::{detect_format, is_tiff_header, SlideFormat};
74pub use format::{
75    is_abbreviated_stream, is_complete_stream, merge_jpeg_tables, prepare_tile_jpeg,
76    GenericTiffLevelData, GenericTiffReader, SvsLevelData, SvsMetadata, SvsReader,
77};
78pub use io::{create_s3_client, BlockCache, RangeReader, S3RangeReader};
79pub use server::{
80    auth_middleware, create_dev_router, create_production_router, create_router, health_handler,
81    slide_metadata_handler, slides_handler, tile_handler, AppState, AuthError, AuthQueryParams,
82    ErrorResponse, HealthResponse, LevelMetadataResponse, OptionalAuth, RouterConfig,
83    SignedUrlAuth, SlideMetadataResponse, SlidesQueryParams, SlidesResponse, TilePathParams,
84    TileQueryParams,
85};
86pub use slide::{
87    CachedSlide, LevelInfo, S3SlideSource, SlideListResult, SlideReader, SlideRegistry, SlideSource,
88};
89pub use tile::{
90    clamp_quality, is_valid_quality, JpegTileEncoder, TileCache, TileCacheKey, TileRequest,
91    TileResponse, TileService, DEFAULT_JPEG_QUALITY, DEFAULT_TILE_CACHE_CAPACITY, MAX_JPEG_QUALITY,
92    MIN_JPEG_QUALITY,
93};