When appending to a compressed archive (gzip, brotli, zstd), the tool now handles compression automatically. Since some compression formats don't support appending to compressed files in place, we write a new compressed file with all the data and atomically rename it to replace the original (assuming there is enough space on that filesystem). This means you can work with compressed archives the same way as uncompressed ones. Point the tool at your .json.gz file and append values. No manual decompression/recompression needed.
28 lines
585 B
Python
Executable file
28 lines
585 B
Python
Executable file
#!/usr/bin/env python3
|
|
"""
|
|
Generate a JSON state file with N items in each array.
|
|
Output goes to stdout.
|
|
|
|
Usage: ./generate_state.py <n>
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
|
|
def main():
|
|
if len(sys.argv) != 2:
|
|
print("Usage: generate_state.py <n>", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
n = int(sys.argv[1])
|
|
|
|
state = {
|
|
"colors": [f"color_{i}" for i in range(1, n + 1)],
|
|
"numbers": [f"number_{i}" for i in range(1, n + 1)],
|
|
"animals": [f"animal_{i}" for i in range(1, n + 1)],
|
|
}
|
|
|
|
print(json.dumps(state))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|