--- /dev/null
+/*
+ * add a file/files to an sqlite db
+ * in the 'files' table.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+
+#include <sqlite3.h>
+#include "sha256.h"
+
+#include "lzma.h"
+
+void *compresslzma(void *buf, size_t bufsize, size_t *len) {
+ /* xz compress it */
+ size_t outsize;
+ void *outbuf;
+ size_t outlen = 0;
+
+ outsize = lzma_stream_buffer_bound(bufsize);
+ outbuf = malloc(outsize);
+ if (!outbuf) {
+ *len = 0;
+ return NULL;
+ }
+ /* TODO adjust encoding level for size */
+ lzma_easy_buffer_encode(6, LZMA_CHECK_CRC64, NULL,
+ buf, bufsize,
+ outbuf, &outlen, outsize
+ );
+ *len = outlen;
+ return outbuf;
+}
+
+static int callback(void *NotUsed, int argc, char **argv, char **azColName){
+ int i;
+ for(i=0; i<argc; i++){
+ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
+ }
+ printf("\n");
+ return 0;
+}
+
+static char *create_table = "create table if not exists files (hash text primary key, size integer, compression text, content blob)";
+
+struct dbh {
+ sqlite3 *db;
+ char *errmsg;
+ int rc;
+};