- const db_header *hdr = (const db_header *)data;
-
- // TODO: Care about the base path.
- string path = data + sizeof(db_header);
- uint64_t offset = sizeof(db_header) + path.size() + 1 + ntohl(hdr->conf_size);
-
- const char *ptr = data + offset;
- while (ptr < data + len) {
- ptr = handle_directory(ptr, files);
- }
-
- munmap((void *)data, len);
- close(fd);
-}
-
-string zstd_compress(const string &src, string *tempbuf)
-{
- size_t max_size = ZSTD_compressBound(src.size());
- if (tempbuf->size() < max_size) {
- tempbuf->resize(max_size);
- }
- size_t size = ZSTD_compress(&(*tempbuf)[0], max_size, src.data(), src.size(), /*level=*/6);
- return string(tempbuf->data(), size);
-}
-
-void do_build(const char *infile, const char *outfile, int block_size)
-{
- //steady_clock::time_point start = steady_clock::now();
-
- vector<string> files;
- read_mlocate(infile, &files);
- if (false) { // To read a plain text file.
- FILE *fp = fopen(infile, "r");
- while (!feof(fp)) {
- char buf[1024];
- if (fgets(buf, 1024, fp) == nullptr || feof(fp)) {
- break;
- }
- string s(buf);
- if (s.back() == '\n') s.pop_back();
- files.push_back(move(s));