diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-01-08 21:20:41 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-01-08 21:20:41 +0100 |
commit | ad75f70efce21330f8d5971d065df97e0c1383ca (patch) | |
tree | 98a100ff0a76a9ce724c57fe05d9fdce8e5d0fc2 /src | |
parent | 9e00ddff83b1657ffafe5d390f49f096a5c4e2aa (diff) | |
download | pyexiv2-ad75f70efce21330f8d5971d065df97e0c1383ca.tar.gz |
Preview::writeToFile dumps the preview data to a file.
Diffstat (limited to 'src')
-rw-r--r-- | src/exiv2wrapper.cpp | 10 | ||||
-rw-r--r-- | src/exiv2wrapper.hpp | 2 | ||||
-rw-r--r-- | src/exiv2wrapper_python.cpp | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index 3dbd8b2..26747ae 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -27,6 +27,8 @@ #include "boost/python/stl_iterator.hpp" +#include <fstream> + // Custom error codes for Exiv2 exceptions #define METADATA_NOT_READ 101 #define NON_REPEATABLE 102 @@ -814,6 +816,14 @@ Preview::Preview(const Exiv2::PreviewImage& previewImage) } } +void Preview::writeToFile(const std::string& path) const +{ + std::string filename = path + _extension; + std::ofstream fd(filename.c_str(), std::ios::out); + fd << _data; + fd.close(); +} + // TODO: update the errors code to reflect changes from src/error.cpp in libexiv2 void translateExiv2Error(Exiv2::Error const& error) diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp index eaffeaa..8c7387c 100644 --- a/src/exiv2wrapper.hpp +++ b/src/exiv2wrapper.hpp @@ -135,6 +135,8 @@ class Preview public: Preview(const Exiv2::PreviewImage& previewImage); + void writeToFile(const std::string& path) const; + std::string _mimeType; std::string _extension; unsigned int _size; diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp index a5f9d6d..2a64f3d 100644 --- a/src/exiv2wrapper_python.cpp +++ b/src/exiv2wrapper_python.cpp @@ -100,6 +100,8 @@ BOOST_PYTHON_MODULE(libexiv2python) .def_readonly("size", &Preview::_size) .def_readonly("dimensions", &Preview::_dimensions) .def_readonly("data", &Preview::_data) + + .def("write_to_file", &Preview::writeToFile) ; class_<Image>("Image", init<std::string>()) |