RADisk Storage Adapter
RADisk is GUN’s default storage adapter for Node.js environments. It stores data as files on the file system using an efficient Radix tree structure for fast queries and range lookups.Installation
RADisk is included with GUN and automatically enabled in Node.js environments:Configuration Options
RADisk accepts the following configuration options:Key Options
file (string)
Base directory or file name for storing data.
Default: 'radata'
until / wait (number)
Time in milliseconds to wait before writing batched data to disk. This allows multiple writes to be grouped together.
Default: 250
batch (number)
Maximum number of write operations to batch before forcing a disk write.
Default: 10000
chunk (number)
Maximum size (in bytes) for a single data file before it’s automatically split.
Default: 1048576 (1MB)
max (number)
Maximum size for individual data values.
Default: 90000000 (90MB)
jsonify (boolean)
Whether to use JSON format for storage. When true, data is stored as JSON objects. When false, uses the legacy RAD encoding format.
Default: true
How RADisk Works
File Organization
RADisk creates a directory structure to store your data:%1C- Character code 28 (directory file)%1B- The escape character separating soul and key%21- Exclamation mark (’!’)
Radix Tree Storage
RADisk uses a Radix tree to efficiently organize keys:Automatic File Splitting
When a data file exceeds thechunk size, RADisk automatically splits it:
- Creates a new file for the second half of the keys
- Updates the original file to contain only the first half
- Updates the directory index to track both files
Write Batching
RADisk batches writes to improve performance:- Reduces disk I/O operations
- Improves write performance
- Reduces risk of corruption from partial writes
Storage Interface
RADisk requires a storage interface withget and put methods:
Read and Write Operations
Writing Data
Reading Data
Performance Tuning
High-Throughput Scenarios
For applications with high write volume:Large Data Sets
For applications storing large amounts of data:Low Latency Requirements
For applications requiring fast writes:Data Format
JSON Format (Default)
Withjsonify: true, data is stored as JSON:
RAD Format (Legacy)
Withjsonify: false, data uses the RAD encoding:
!- Field separator (ASCII 31)#- Prefix length indicator"- String value+- Number value:- Value separator
File System Considerations
Directory Structure
Ensure the storage directory exists and has proper permissions:Backup and Recovery
To backup RADisk data:Cleaning Up
RADisk automatically manages file lifecycle, but you can manually clean up if needed:Troubleshooting
Error: “Radisk needs opt.store interface”
You must provide a storage interface:
Error: “Data too big!”
Increase themax option:
Corrupt File Recovery
RADisk automatically detects and removes corrupt files:Best Practices
- Use appropriate chunk sizes: Smaller chunks for many small writes, larger chunks for fewer large writes
- Enable batching: Keep
untilat 250ms or higher for better performance - Backup regularly: Use file system snapshots or regular backups
- Monitor disk space: RADisk can grow based on your data
- Use JSON format: The default JSON format is more debuggable than RAD format
Next Steps
Rindexed Adapter
Browser storage with IndexedDB
S3 Adapter
Cloud storage with Amazon S3
Custom Adapters
Build your own storage adapter
Performance
Optimize GUN performance