diff --git a/include/qpdf/InputSource.hh b/include/qpdf/InputSource.hh index 94817155..1cbf1cf9 100644 --- a/include/qpdf/InputSource.hh +++ b/include/qpdf/InputSource.hh @@ -79,6 +79,8 @@ class QPDF_DLL_CLASS InputSource virtual void unreadCh(char ch) = 0; // The following methods are for internal use by qpdf only. + inline size_t read(std::string& str, size_t count, qpdf_offset_t at = -1); + inline std::string read(size_t count, qpdf_offset_t at = -1); inline qpdf_offset_t fastTell(); inline bool fastRead(char&); inline void fastUnread(bool); diff --git a/libqpdf/qpdf/InputSource_private.hh b/libqpdf/qpdf/InputSource_private.hh index a81efe40..61946157 100644 --- a/libqpdf/qpdf/InputSource_private.hh +++ b/libqpdf/qpdf/InputSource_private.hh @@ -3,6 +3,25 @@ #include +inline size_t +InputSource::read(std::string& str, size_t count, qpdf_offset_t at) +{ + if (at >= 0) { + seek(at, SEEK_SET); + } + str.resize(count); + str.resize(read(str.data(), count)); + return str.size(); +} + +inline std::string +InputSource::read(size_t count, qpdf_offset_t at) +{ + std::string result(count, '\0'); + (void)read(result, count, at); + return result; +} + inline void InputSource::loadBuffer() {