nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | README | LICENSE

commit 76eba1df2aa1049c0de5eadada4624347f74dab4
parent f56f983a5688c367bb1c8e9f5e6cbf5fe6ac3062
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 22 Jul 2023 08:49:48 -0700

write ndb record for testing purposes

Diffstat:
M.gitignore | 1+
MMakefile | 2+-
Mio.h | 20+++++++++++++++-----
Mtest.c | 4++++
4 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -5,3 +5,4 @@ test .envrc shell.nix *.dSYM +test_contacts_ndb_note diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -CFLAGS = -Wall -Wno-unused-function -Werror -O1 -g +CFLAGS = -Wall -Wno-unused-function -Werror -O2 -g check: test ./test diff --git a/io.h b/io.h @@ -16,18 +16,28 @@ static int read_fd(FILE *fd, unsigned char *buf, int buflen, int *written) return 1; } +static int write_file(const char *filename, unsigned char *buf, int buflen) +{ + FILE *file = NULL; + int ok; + + file = fopen(filename, "w"); + if (file == NULL) + return 0; + + ok = fwrite(buf, buflen, 1, file); + fclose(file); + return ok; +} + static int read_file(const char *filename, unsigned char *buf, int buflen, int *written) { FILE *file = NULL; int ok; file = fopen(filename, "r"); - if (file == NULL) { - *written = strlen(filename)+1; - memcpy(buf, filename, *written); - buf[*written-1] = '\n'; + if (file == NULL) return 1; - } ok = read_fd(file, buf, buflen, written); fclose(file); diff --git a/test.c b/test.c @@ -108,6 +108,10 @@ static void test_parse_contact_list() size = ndb_note_from_json((const char*)json, written, &note, buf, alloc_size); printf("ndb_note_from_json size %d\n", size); assert(size > 0); + assert(size == 59106); + + printf("contacts content '%s'\n", ndb_note_content(note)); + write_file("test_contacts_ndb_note", (unsigned char *)note, size); free(json); free(buf);