Skip to content

Commit 6d12777

Browse files
authored
Merge branch 'main' into test/nip62-vanish-integration
2 parents cf4b68d + 214bef5 commit 6d12777

15 files changed

Lines changed: 1430 additions & 94 deletions

.changeset/quick-maps-marry.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"nostream": minor
3+
---
4+
5+
Add gzip and xz compression support to event import/export flows.
6+
7+
- Export supports `--compress`/`-z` with `--format gzip|gz|xz`.
8+
- Import auto-detects compressed input by extension and magic bytes and decompresses in a stream pipeline.
9+
- Includes docs updates and unit/integration test coverage for compression paths.

.knip.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"project": [
99
"src/**/*.ts"
1010
],
11+
"ignoreDependencies": [
12+
"lzma-native"
13+
],
1114
"ignoreFiles": [],
1215
"commitlint": false,
1316
"eslint": false,

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,23 @@ Print the I2P hostname:
249249
250250
### Importing events from JSON Lines
251251
252-
You can import NIP-01 events from a `.jsonl` file directly into the relay database.
252+
You can import NIP-01 events from `.jsonl` files directly into the relay database.
253+
Compressed files are also supported and decompressed on-the-fly:
254+
255+
- `.jsonl.gz` (Gzip)
256+
- `.jsonl.xz` (XZ)
253257
254258
Basic import:
255259
```
256260
npm run import -- ./events.jsonl
257261
```
258262
263+
Import a compressed backup:
264+
```
265+
npm run import -- ./events.jsonl.gz
266+
npm run import -- ./events.jsonl.xz
267+
```
268+
259269
Set a custom batch size (default: `1000`):
260270
```
261271
npm run import -- ./events.jsonl --batch-size 500
@@ -639,16 +649,42 @@ To observe client and subscription counts in real-time during a test, you can in
639649
```bash
640650
docker compose logs -f nostream
641651
```
642-
643652
## Export Events
644653

645654
Export all stored events to a [JSON Lines](https://jsonlines.org/) (`.jsonl`) file. Each line is a valid NIP-01 Nostr event JSON object. The export streams rows from the database using cursors, so it works safely on relays with millions of events without loading them into memory.
646655

656+
Optional compression is supported for lower storage and transfer costs:
657+
658+
- Gzip via Node's native `zlib`
659+
- XZ via `lzma-native`
660+
647661
```
648662
npm run export # writes to events.jsonl
649663
npm run export -- backup-2024-01-01.jsonl # custom filename
664+
npm run export -- backup.jsonl.gz --compress --format=gzip
665+
npm run export -- backup.jsonl.xz --compress --format=xz
650666
```
651667

668+
Flags:
669+
670+
- `--compress` / `-z`: enable compression.
671+
- `--format <gzip|gz|xz>`: compression format. If omitted while compression is enabled,
672+
format is inferred from file extension (`.gz` / `.xz`) and defaults to `gzip`.
673+
674+
After completion, the exporter prints a summary with:
675+
676+
- Raw bytes generated from JSONL lines
677+
- Output bytes written to disk
678+
- Compression delta (smaller/larger)
679+
- Throughput in events/sec and bytes/sec
680+
681+
Optional XZ tuning (environment variables):
682+
683+
- `NOSTREAM_XZ_THREADS`: max worker threads for XZ compression.
684+
Defaults to `4` and is automatically capped to available CPU cores minus one.
685+
- `NOSTREAM_XZ_PRESET`: compression preset from `0` (fastest, larger output)
686+
to `9` (slowest, smallest output). Default is `6`.
687+
652688
The script reads the same `DB_*` environment variables used by the relay (see [CONFIGURATION.md](CONFIGURATION.md)).
653689

654690
## Benchmark Database Queries

package-lock.json

Lines changed: 55 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
"ws": "^8.18.0",
143143
"zod": "^3.22.4"
144144
},
145+
"optionalDependencies": {
146+
"lzma-native": "^8.0.6"
147+
},
145148
"overrides": {
146149
"axios@<0.31.0": ">=0.31.0"
147150
}

0 commit comments

Comments
 (0)