diff --git a/src/RdaReader/include/RdaReader.hpp b/src/RdaReader/include/RdaReader.hpp index 4904f75..a06635e 100644 --- a/src/RdaReader/include/RdaReader.hpp +++ b/src/RdaReader/include/RdaReader.hpp @@ -15,25 +15,25 @@ class RdaReader { const std::vector &datasetName, const std::vector &sharedIndex, const std::vector &rdas, - std::ostream &output + const std::function output ); size_t readDataset( const std::vector &datasetName, const std::vector &sharedIndex, const std::vector &rdas, - std::ostream &output, + const std::function output, std::mutex &outputMutex ); size_t readRda( std::istream &rda, uint64_t id, - std::ostream &output + const std::function output ); size_t readRda( std::istream &rda, uint64_t id, - std::ostream &output, + const std::function output, std::mutex &outputMutex ); private: diff --git a/src/RdaReader/src/RdaReader.cpp b/src/RdaReader/src/RdaReader.cpp index 997d148..e9d8ae9 100644 --- a/src/RdaReader/src/RdaReader.cpp +++ b/src/RdaReader/src/RdaReader.cpp @@ -17,7 +17,7 @@ RdaReader::RdaReader() : logger(nullptr) {} RdaReader::RdaReader(std::function logger) : logger(logger) {} -size_t RdaReader::readRda(std::istream &rda, uint64_t id, std::ostream &output, std::mutex &outputMutex) { +size_t RdaReader::readRda(std::istream &rda, uint64_t id, const std::function output, std::mutex &outputMutex) { log("Reading an rda\n"); BucketedZstdData bucket(rda); @@ -25,7 +25,8 @@ size_t RdaReader::readRda(std::istream &rda, uint64_t id, std::ostream &output, const std::lock_guard lock(outputMutex); log("Writing " + std::to_string(data.value().size()) + " entries to output\n"); for(const auto &entry : data.value()) { - output.write(entry.data(), entry.size()) << '\n'; + output(entry.data(), entry.size()); + output("\n", 1); } log("Done writing entries\n"); return data.value().size(); @@ -34,7 +35,7 @@ size_t RdaReader::readRda(std::istream &rda, uint64_t id, std::ostream &output, return 0; } -size_t RdaReader::readRda(std::istream &rda, uint64_t id, std::ostream &output) { +size_t RdaReader::readRda(std::istream &rda, uint64_t id, const std::function output) { std::mutex dummyMutex; return readRda(rda, id, output, dummyMutex); } @@ -49,7 +50,7 @@ std::optional getVictimIfAvailable(std::vector & return {}; } -size_t RdaReader::readDataset(const std::vector &datasetName, const std::vector &sharedIndex, const std::vector &rdas, std::ostream &output, std::mutex &outputMutex) { +size_t RdaReader::readDataset(const std::vector &datasetName, const std::vector &sharedIndex, const std::vector &rdas, const std::function output, std::mutex &outputMutex) { log("Reading shared index... "); SharedIndex sharedIndexReader(sharedIndex); @@ -79,7 +80,7 @@ size_t RdaReader::readDataset(const std::vector &datasetName, const std::v return 0; } -size_t RdaReader::readDataset(const std::vector &datasetName, const std::vector &sharedIndex, const std::vector &rdas, std::ostream &output) { +size_t RdaReader::readDataset(const std::vector &datasetName, const std::vector &sharedIndex, const std::vector &rdas, const std::function output) { std::mutex dummyMutex; return readDataset(datasetName, sharedIndex, rdas, output, dummyMutex); } \ No newline at end of file diff --git a/src/rdaExtractor/src/rdaExtractor.cpp b/src/rdaExtractor/src/rdaExtractor.cpp index 508ecfa..afa7693 100644 --- a/src/rdaExtractor/src/rdaExtractor.cpp +++ b/src/rdaExtractor/src/rdaExtractor.cpp @@ -72,7 +72,7 @@ int main(int argc, char **argv) { rdaRefs.push_back(&stream); } RdaReader rdaReader(threadedLog); - if(size_t totalRead = rdaReader.readDataset(datasetName, sharedIndexData, rdaRefs, std::cout)) { + if(size_t totalRead = rdaReader.readDataset(datasetName, sharedIndexData, rdaRefs, [](const char *s, size_t n){std::cout.write(s, n);})) { std::cerr << "Found a total of " << totalRead << " entries" << std::endl; } else { std::cerr << "Cannot find '" << argv[1] << "' in the shared index" << std::endl;