Skip to content

drdhaval2785/dictd_reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dictd_reader

A Dart package for reading DICTD dictionary files (.index and .dict/.dict.dz).

Features

  • Efficient Index Parsing: Parse DICTD .index files to get word offsets and lengths.
  • Gzipped Index Support: Automatically handles .index.gz files in-situ.
  • Random Access Reading: Read definitions from .dict files efficiently.
  • In-situ Compressed Reading: Full support for .dict.dz (dictzip) files without decompression, using the dictzip_reader package.
  • Lightweight: Pure Dart implementation, no Flutter dependency.

Getting started

Add dictd_reader to your pubspec.yaml:

dependencies:
  dictd_reader: ^0.1.0

Usage

Parsing an Index File

The 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']}');
  }
}

Reading a Definition

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();

License

This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.

Github

https://github.com/drdhaval2785/dictd_reader

About

.dictd file reader for dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages