|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +snappy-java is a Java port of Google's Snappy compression library, providing fast compression/decompression with JNI bindings for native performance across multiple platforms. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +### Using sbt (primary build tool) |
| 12 | + |
| 13 | +```bash |
| 14 | +# Enter sbt console |
| 15 | +./sbt |
| 16 | + |
| 17 | +# Run tests |
| 18 | +./sbt test |
| 19 | + |
| 20 | +# Run tests matching a pattern |
| 21 | +./sbt "testOnly *BitShuffleTest" |
| 22 | + |
| 23 | +# Create jar file |
| 24 | +./sbt package |
| 25 | + |
| 26 | +# Publish to local Maven repository |
| 27 | +./sbt publishM2 |
| 28 | + |
| 29 | +# Run tests continuously on code changes |
| 30 | +./sbt "~test" |
| 31 | +``` |
| 32 | + |
| 33 | +### Using make (for native library compilation) |
| 34 | + |
| 35 | +```bash |
| 36 | +# Build native libraries |
| 37 | +make |
| 38 | + |
| 39 | +# Clean build artifacts |
| 40 | +make clean |
| 41 | + |
| 42 | +# Platform-specific builds (when cross-compiling) |
| 43 | +make native-all |
| 44 | +``` |
| 45 | + |
| 46 | +## Architecture |
| 47 | + |
| 48 | +### Core Components |
| 49 | + |
| 50 | +1. **Java API Layer** (`src/main/java/org/xerial/snappy/`) |
| 51 | + - `Snappy.java`: Main API facade providing high-level compression/decompression methods |
| 52 | + - `SnappyNative.java`: JNI interface to native Snappy library |
| 53 | + - `SnappyLoader.java`: Handles platform-specific native library loading |
| 54 | + |
| 55 | +2. **Native Layer** (`src/main/java/org/xerial/snappy/`) |
| 56 | + - `SnappyNative.cpp`: JNI implementation bridging Java and C++ Snappy |
| 57 | + - `BitShuffleNative.cpp`: JNI implementation for BitShuffle algorithm |
| 58 | + |
| 59 | +3. **Stream API** (`src/main/java/org/xerial/snappy/`) |
| 60 | + - `SnappyOutputStream`/`SnappyInputStream`: Block-based compression streams |
| 61 | + - `SnappyFramedOutputStream`/`SnappyFramedInputStream`: Framing format implementation |
| 62 | + - `SnappyHadoopCompatibleOutputStream`: Hadoop-compatible format |
| 63 | + |
| 64 | +4. **Memory Management** (`src/main/java/org/xerial/snappy/buffer/` and `/pool/`) |
| 65 | + - Buffer allocation and pooling for efficient memory usage |
| 66 | + - Direct ByteBuffer management for zero-copy operations |
| 67 | + |
| 68 | +### Platform Support |
| 69 | + |
| 70 | +The project includes pre-built native libraries for multiple platforms in `src/main/resources/org/xerial/snappy/native/`: |
| 71 | +- Windows (x86, x86_64, aarch64) |
| 72 | +- macOS (x86, x86_64, aarch64) |
| 73 | +- Linux (x86, x86_64, aarch64, arm, armv6, armv7, ppc64, ppc64le, s390x, riscv64, loongarch64) |
| 74 | +- AIX (ppc, ppc64) |
| 75 | +- SunOS (x86, x86_64, sparc) |
| 76 | +- Android (arm, aarch64) |
| 77 | + |
| 78 | +### Cross-compilation |
| 79 | + |
| 80 | +The project uses Docker-based cross-compilation toolchains (see `docker/` directory) for building native libraries across different architectures. |
| 81 | + |
| 82 | +## Testing |
| 83 | + |
| 84 | +```bash |
| 85 | +# Run all tests with debug logging |
| 86 | +./sbt "testOnly * -- -l debug" |
| 87 | + |
| 88 | +# Run specific test class |
| 89 | +./sbt "testOnly org.xerial.snappy.SnappyTest" |
| 90 | + |
| 91 | +# The project uses AirSpec (for Scala tests) and JUnit (for Java tests) |
| 92 | +# Tests are located in src/test/java/org/xerial/snappy/ |
| 93 | +``` |
| 94 | + |
| 95 | +## Important Notes |
| 96 | + |
| 97 | +1. **Native Library Loading**: The project automatically detects the platform and loads the appropriate native library from resources |
| 98 | +2. **Memory Safety**: Uses direct ByteBuffers for efficient memory operations - be aware of buffer boundaries |
| 99 | +3. **Thread Safety**: Snappy compression/decompression methods are thread-safe as they don't maintain state |
| 100 | +4. **OSGi Support**: The project includes OSGi bundle configuration in build.sbt |
| 101 | +5. **Compatibility**: Multiple stream formats are supported - ensure you use matching read/write formats (see compatibility matrix in README.md) |
0 commit comments