https://github.com/pmarkert/cdbsharp
Library for reading/writing CDB (Constant Database) files
https://github.com/pmarkert/cdbsharp
Last synced: 6 months ago
JSON representation
Library for reading/writing CDB (Constant Database) files
- Host: GitHub
- URL: https://github.com/pmarkert/cdbsharp
- Owner: pmarkert
- Created: 2012-05-19T02:56:06.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2012-05-19T03:12:49.000Z (about 14 years ago)
- Last Synced: 2025-01-30T02:42:48.308Z (over 1 year ago)
- Size: 97.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
CDBSharp
========
Library for reading/writing CDB (Constant Database) files
```c#
class Program {
static void Main(string[] args) {
using (var writer = new StringCDBWriter("verses.cdb")) {
foreach (var verse in parseVerses(new StreamReader(new GZipStream(new WebClient().OpenRead("https://s3.amazonaws.com/mongol.ephisys.com/Data/kjv.rawtxt.gz"), CompressionMode.Decompress)))) {
writer.AddEntry(verse.Key, verse.Value);
}
}
using (var cdb = new StringCDBReader("verses.cdb")) {
Console.WriteLine(cdb.Find("John3:16").Single());
}
}
private static IEnumerable> parseVerses(StreamReader sr) {
// Iterator to return verses as long as we keep finding more. Loads about 31,000 verses.
while (!sr.EndOfStream) {
var match = Regex.Match(sr.ReadLine(), @"(?\d*[A-Za-z]+\d+:\d+)\s(?.+$)");
if (match.Success) {
yield return new KeyValuePair(match.Groups["Reference"].Value, match.Groups["Verse"].Value);
}
}
}
}
```