An HTTP server to display zip files as folders, making it easy to serve compact static archives.
cmpserve is a lightweight HTTP server designed to serve ZIP files as they were directories. It also would serve files and directories. ZIP archives get indexed for quicker random access.
Optionally cmpserve can display directory indexes and expose hidden files.
- Serves files and directories over HTTP.
- Supports ZIP file indexing for fast access.
- Allows optional directory listing.
- Configurable options for hidden files and indexing.
- Caches ZIP file metadata using SQLite.
- Supports configuration via environment variables.
cmpserve/
│── main.go # Entry point of the application
│── internal/
│ ├── service/
│ │ ├── service.go # HTTP handler and service initialization
│ ├── readers/
│ │ ├── zipfast/
│ │ │ ├── fast_zip_reader.go # Optimized ZIP file reader with SQLite index
cmpserve accepts several optional command-line flags:
| Flag | Default Value | Description |
|---|---|---|
-dir |
. |
Root directory to serve |
-cache-dir |
. |
Directory for cache storage |
-addr |
0.0.0.0 |
Bind address for the server |
-port |
8080 |
Port to listen on |
-indexes |
false |
Whether to display directory indexes |
-show-hidden-files |
false |
Whether to serve hidden files |
As an alternative to command-line flags, cmpserve allows configuration using environment variables. Command-line flags take precedence over environment variables.
| Environment Variable | Default Value | Description |
|---|---|---|
CMPSERVE_DIR |
. |
Root directory to serve |
CMPSERVE_CACHE_DIR |
. |
Directory for cache storage |
CMPSERVE_ADDR |
0.0.0.0 |
Bind address for the server |
CMPSERVE_PORT |
8080 |
Port to listen on |
CMPSERVE_INDEXES |
false |
Whether to display directory indexes (set to true to enable) |
CMPSERVE_SHOW_HIDDEN_FILES |
false |
Whether to serve hidden files (set to true to enable) |
Run the server with:
./cmpserve -dir=/path/to/serve -cache-dir=/path/to/cache -port=9090Or using environment variables:
export CMPSERVE_DIR="/path/to/serve"
export CMPSERVE_CACHE_DIR="/path/to/cache"
export CMPSERVE_PORT="9090"
./cmpserveHandles command-line arguments, initializes the service, and starts an HTTP server.
- Implements
ServeHTTP, handling file requests, directory indexing, and ZIP file streaming. - Routes requests based on path structure.
- Supports automatic directory listing when enabled.
- Uses SQLite to store metadata of ZIP archives.
- Caches ZIP file entries to enable quick retrieval.
- Provides
StreamFilefor extracting and serving specific files from ZIP archives. - Supports
DeflateandStorecompression methods.
- Directories are served with index listings if
-indexesis enabled. - ZIP files are dynamically indexed and extracted on request.
If a requested path points to a file inside a ZIP archive, the server:
- Checks if the ZIP file is indexed.
- If not, indexes it and caches the metadata.
- Streams the requested file from the archive.
- If a directory is requested, it displays an index if enabled.
- If
show-hidden-filesis disabled, hidden files are omitted.
- Logs initialization failures.
- Returns
404 Not Foundfor missing files or inaccessible paths. - Returns
500 Internal Server Errorfor database or indexing issues.