| 54 | } |
| 55 | |
| 56 | CSVReaderFromKey::CSVReaderFromKey( |
| 57 | std::shared_ptr<Stream> stream, |
| 58 | const std::string& key, |
| 59 | char sep, |
| 60 | char quote, |
| 61 | bool fromMemory, |
| 62 | const std::filesystem::path& local_prefix, |
| 63 | const std::shared_ptr<core::FileFetcher>& fetcher) |
| 64 | : Compose(stream, [=](const Sample& sample) { |
| 65 | if (fromMemory) { |
| 66 | auto array = |
| 67 | sample::check_key(sample, key, mlx::data::ArrayType::UInt8); |
| 68 | auto ms = std::make_shared<core::imemstream>(array); |
| 69 | return std::make_shared<CSVReader>(ms, sep, quote); |
| 70 | } else { |
| 71 | auto array = |
| 72 | sample::check_key(sample, key, mlx::data::ArrayType::Int8); |
| 73 | std::string filename( |
| 74 | reinterpret_cast<char*>(array->data()), array->size()); |
| 75 | return std::make_shared<CSVReader>( |
| 76 | filename, sep, quote, local_prefix, fetcher); |
| 77 | } |
| 78 | }) {} |
| 79 | |
| 80 | } // namespace stream |
| 81 | } // namespace data |