diff --git a/src/BucketedZstdData.cpp b/src/BucketedZstdData.cpp index cc18332..4d4c6eb 100644 --- a/src/BucketedZstdData.cpp +++ b/src/BucketedZstdData.cpp @@ -8,26 +8,26 @@ constexpr int headerSize = sizeof(uint32_t); constexpr int indexEntrySize = sizeof(uint64_t)*2; -BucketedZstdData::BucketedZstdData(std::ifstream &file) : file(file) {} +BucketedZstdData::BucketedZstdData(std::istream &input) : input(input) {} std::optional> BucketedZstdData::getDatasetWithId(std::uint32_t id) { - file.seekg(0, std::ios::beg); + input.seekg(0, std::ios::beg); uint32_t indexSize; - file.read((char *)&indexSize, sizeof(indexSize)); + input.read((char *)&indexSize, sizeof(indexSize)); if(indexSize < id) return {}; //seek to index entry - file.seekg(sizeof(uint32_t) + indexEntrySize*id, std::ios::beg); + input.seekg(sizeof(uint32_t) + indexEntrySize*id, std::ios::beg); uint64_t offset, length; - file.read((char *)&offset, sizeof(offset)); - file.read((char *)&length, sizeof(length)); + input.read((char *)&offset, sizeof(offset)); + input.read((char *)&length, sizeof(length)); if(length == 0) return {}; - file.seekg(offset + headerSize + indexSize * indexEntrySize, std::ios::beg); + input.seekg(offset + headerSize + indexSize * indexEntrySize, std::ios::beg); std::vector inBuf(length); - file.read(inBuf.data(), inBuf.size()); + input.read(inBuf.data(), inBuf.size()); std::vector output(ZSTD_getFrameContentSize(inBuf.data(), inBuf.size())); if(!ZSTD_isError(ZSTD_decompress(output.data(), output.size(), inBuf.data(), inBuf.size()))) { diff --git a/src/BucketedZstdData.hpp b/src/BucketedZstdData.hpp index 4fc54f8..6e3dd0e 100644 --- a/src/BucketedZstdData.hpp +++ b/src/BucketedZstdData.hpp @@ -8,11 +8,11 @@ class BucketedZstdData { public: - BucketedZstdData(std::ifstream &file); + BucketedZstdData(std::istream &input); std::optional> getDatasetWithId(std::uint32_t id); std::optional>> getEntriesByID(std::uint32_t id); private: - std::ifstream &file; + std::istream &input; }; #endif \ No newline at end of file diff --git a/src/spices.cpp b/src/spices.cpp index b406e1b..c2ca59a 100644 --- a/src/spices.cpp +++ b/src/spices.cpp @@ -46,17 +46,20 @@ std::optional> readSharedIndex(const std::filesystem::path &fi void processRDA(const std::filesystem::directory_entry &file, std::atomic_size_t &totalEntries, uint64_t id, std::mutex &outputMutex) { if(file.path().extension() == ".rda") { + std::string fileName(file.path().filename()); std::ifstream fileStream(file.path(), std::ios::binary); - CERRLOG("Reading %s\n", std::string(file.path().filename()).c_str()); + CERRLOG("Reading %s\n", fileName.c_str()); BucketedZstdData bucket(fileStream); if(std::optional>> data = bucket.getEntriesByID(id)) { totalEntries += data.value().size(); const std::lock_guard lock(outputMutex); - CERRLOG("Writing %s\n", std::string(file.path().filename()).c_str()); + CERRLOG("Writing %s\n", fileName.c_str()); for(const auto &entry : data.value()) { std::cout.write(entry.data(), entry.size()) << '\n'; } + } else { + CERRLOG("No entries found in %s\n", fileName.c_str()); } } }