diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2015-03-09 22:29:34 -0700 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2015-03-09 22:33:37 -0700 |
commit | a3959cc57349176d5e869029342ddfd2576eedc6 (patch) | |
tree | fe12cc470c225d35791dfffad252c036336de127 /src/core | |
parent | e24db786cfb3886be40028bde9a16073fb32fe5e (diff) |
API to write to file
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/basetypes/MCData.cpp | 10 | ||||
-rw-r--r-- | src/core/basetypes/MCData.h | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/core/basetypes/MCData.cpp b/src/core/basetypes/MCData.cpp index 8b689036..be4497a7 100644 --- a/src/core/basetypes/MCData.cpp +++ b/src/core/basetypes/MCData.cpp @@ -718,6 +718,16 @@ void Data::importSerializable(HashMap * serializable) setData(((String *) (serializable->objectForKey(MCSTR("data"))))->decodedBase64Data()); } +ErrorCode Data::writeToFile(String * filename) +{ + FILE * f = fopen(filename->fileSystemRepresentation(), "wb"); + size_t result = fwrite(bytes(), length(), 1, f); + if (result == 0) { + return ErrorFile; + } + return ErrorNone; +} + #if __APPLE__ static CFStringEncoding encodingFromCString(const char * charset) { diff --git a/src/core/basetypes/MCData.h b/src/core/basetypes/MCData.h index bec75008..0bb1bc07 100644 --- a/src/core/basetypes/MCData.h +++ b/src/core/basetypes/MCData.h @@ -44,6 +44,8 @@ namespace mailcore { virtual Data * decodedDataUsingEncoding(Encoding encoding); virtual String * base64String(); + + virtual ErrorCode writeToFile(String * filename); public: // private virtual String * charsetWithFilteredHTML(bool filterHTML, String * hintCharset = NULL); |