# Session 18: File Store

## Summary

The persistent file-based storage engine for JetStream. Handles message persistence, compaction, encryption, compression, and recovery. This is the largest single-file session.

## Scope

| Go File | Features | Feature IDs | Go LOC |
|---------|----------|-------------|--------|
| server/filestore.go | 312 | 951–1262 | 11,421 |
| **Total** | **312** | | **11,421** |

## .NET Classes

- `JetStreamFileStore` — file-based stream store (174 features, 7,255 LOC)
- `MessageBlock` — individual message block on disk (95 features, 3,314 LOC)
- `ConsumerFileStore` — file-based consumer store (33 features, 700 LOC)
- `CompressionInfo` — compression metadata
- `ErrBadMsg` — bad message error type

## Test Files

| Test File | Tests | Test IDs |
|-----------|-------|----------|
| server/filestore_test.go | 249 | 351–599 |
| **Total** | **249** | |

## Dependencies

- Session 01 (Foundation Types)
- Session 02 (Utilities)
- Session 17 (Store Interfaces)

## .NET Target Location

- `dotnet/src/ZB.MOM.NatsNet.Server/JetStream/Storage/`

## Notes

- **This is a multi-sitting session** — 11.4K Go LOC and 249 tests
- Suggested sub-batching:
  - **18a**: `MessageBlock` (95 features, 3.3K LOC) — the on-disk block format
  - **18b**: `JetStreamFileStore` core (load, store, recover, compact) — ~90 features
  - **18c**: `JetStreamFileStore` remaining (snapshots, encryption, purge) — ~84 features
  - **18d**: `ConsumerFileStore` (33 features, 700 LOC)
  - **18e**: Tests (249 tests)
- File I/O should use `FileStream` with `RandomAccess` APIs for .NET 10
- Encryption maps to `System.Security.Cryptography`
- S2/Snappy compression maps to existing NuGet packages
