A Dart package for reading DICTD dictionary files (.index and .dict/.dict.dz).
- Efficient Index Parsing: Parse DICTD
.indexfiles to get word offsets and lengths. - Gzipped Index Support: Automatically handles
.index.gzfiles in-situ. - Random Access Reading: Read definitions from
.dictfiles efficiently. - In-situ Compressed Reading: Full support for
.dict.dz(dictzip) files without decompression, using thedictzip_readerpackage. - Lightweight: Pure Dart implementation, no Flutter dependency.
Add dictd_reader to your pubspec.yaml:
dependencies:
dictd_reader: ^0.1.0The DictdParser can handle both plain .index and compressed .index.gz files.
import 'package:dictd_reader/dictd_reader.dart';
void main() async {
final parser = DictdParser();
// Works with both .index and .index.gz
await for (final entry in parser.parseIndex('path/to/dictionary.index.gz')) {
print('Word: ${entry['word']}, Offset: ${entry['offset']}, Length: ${entry['length']}');
}
}The DictdReader automatically detects if a file is compressed (.dz or .gz) and uses dictzip_reader for efficient random access if it is.
import 'package:dictd_reader/dictd_reader.dart';
void main() async {
// Works with .dict, .dict.dz, and .dict.gz
final reader = DictdReader('path/to/dictionary.dict.dz');
await reader.open();
// Read definition at a specific offset and length (usually obtained from the index)
final definition = await reader.readAtOffset(1234, 567);
print(definition);
await reader.close();
}final entries = [ (offset: 0, length: 5), (offset: 5, length: 5), ]; final definitions = await reader.readEntries(entries);
### Random Access Source (SAF Support)
To support non-file-based reading (like Android Storage Access Framework), you can implement `RandomAccessSource`:
```dart
final reader = DictdReader('path/to/dict');
// MyCustomSource implements RandomAccessSource
await reader.openSource(MyCustomSource());
final definition = await reader.readAtOffset(offset, length);
Default file-based implementation is provided:
await reader.openSource(FileRandomAccessSource('path/to/dict'));
// Equivalent to:
// await reader.open();This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.