|
33 | 33 | #include <pybind11/stl.h> |
34 | 34 |
|
35 | 35 | #include <vrs/os/Platform.h> |
| 36 | +#include <vrs/utils/FilterCopy.h> |
36 | 37 |
|
| 38 | +#include "../VrsBindings.h" |
| 39 | +#include "../reader/VRSReader.h" |
37 | 40 | #include "PyRecordable.h" |
38 | 41 | #include "VRSWriter.h" |
39 | 42 |
|
@@ -73,6 +76,38 @@ using namespace vrs; |
73 | 76 | })); |
74 | 77 |
|
75 | 78 | void pybind_writer(py::module& m) { |
| 79 | + m.def( |
| 80 | + "verbatim_copy", |
| 81 | + [](const std::string& inputPath, |
| 82 | + const std::string& outputPath, |
| 83 | + const std::vector<std::string>& streamIds) { |
| 84 | + initVrsBindings(); |
| 85 | + vrs::utils::FilteredFileReader filteredReader(inputPath); |
| 86 | + int status = filteredReader.openFile(); |
| 87 | + if (status != 0) { |
| 88 | + throw py::value_error("Failed to open input file: " + inputPath); |
| 89 | + } |
| 90 | + if (!streamIds.empty()) { |
| 91 | + filteredReader.filter.streams.clear(); |
| 92 | + for (const auto& sid : streamIds) { |
| 93 | + auto id = StreamId::fromNumericName(sid); |
| 94 | + if (!id.isValid()) { |
| 95 | + throw py::value_error("Invalid stream ID: " + sid); |
| 96 | + } |
| 97 | + filteredReader.filter.streams.insert(id); |
| 98 | + } |
| 99 | + } |
| 100 | + vrs::utils::CopyOptions copyOptions(false); |
| 101 | + status = vrs::utils::filterCopy(filteredReader, outputPath, copyOptions); |
| 102 | + if (status != 0) { |
| 103 | + throw std::runtime_error("verbatim_copy failed with error code " + to_string(status)); |
| 104 | + } |
| 105 | + return status; |
| 106 | + }, |
| 107 | + py::arg("input_path"), |
| 108 | + py::arg("output_path"), |
| 109 | + py::arg("stream_ids") = std::vector<std::string>{}); |
| 110 | + |
76 | 111 | py::class_<pyvrs::PyRecordFormat, std::unique_ptr<pyvrs::PyRecordFormat, py::nodelete>>( |
77 | 112 | m, "RecordFormat") |
78 | 113 | .def("getMembers", &pyvrs::PyRecordFormat::getMembers) |
@@ -112,6 +147,16 @@ void pybind_writer(py::module& m) { |
112 | 147 | .def("writeRecords", &pyvrs::VRSWriter::writeRecords) |
113 | 148 | .def("getBackgroundThreadQueueByteSize", &pyvrs::VRSWriter::getBackgroundThreadQueueByteSize) |
114 | 149 | .def("close", &pyvrs::VRSWriter::close) |
| 150 | + .def( |
| 151 | + "addVerbatimCopyStreams", |
| 152 | + [](pyvrs::VRSWriter& self, |
| 153 | + PyVRSReader& reader, |
| 154 | + const std::vector<std::string>& streamIds) { |
| 155 | + return self.addVerbatimCopyStreams(reader.getRecordFileReader(), streamIds); |
| 156 | + }, |
| 157 | + py::arg("reader"), |
| 158 | + py::arg("stream_ids")) |
| 159 | + .def("copyVerbatimRecords", &pyvrs::VRSWriter::copyVerbatimRecords) |
115 | 160 | #if IS_VRS_FB_INTERNAL() |
116 | 161 | #include "Writer_fb.hpp" |
117 | 162 | #endif |
|
0 commit comments